diff --git a/src/Core/src/Platform/iOS/MauiTextView.cs b/src/Core/src/Platform/iOS/MauiTextView.cs index f3a7d4380e26..066ef6810620 100644 --- a/src/Core/src/Platform/iOS/MauiTextView.cs +++ b/src/Core/src/Platform/iOS/MauiTextView.cs @@ -10,6 +10,7 @@ namespace Microsoft.Maui.Platform public class MauiTextView : UITextView { readonly UILabel _placeholderLabel; + nfloat _defaultPlaceholderSize = -1; public MauiTextView() { @@ -80,6 +81,17 @@ public override string? Text } } + public override UIFont? Font + { + get => base.Font; + set + { + base.Font = value; + UpdatePlaceholderFontSize(value); + + } + } + public override NSAttributedString AttributedText { get => base.AttributedText; @@ -161,5 +173,21 @@ void ShouldCenterVertically() _ => new CGPoint(0, 0), }; } + + void UpdatePlaceholderFontSize(UIFont? value) + { + if (value != null) + { + if (_defaultPlaceholderSize == -1) + { + _defaultPlaceholderSize = _placeholderLabel.Font.PointSize; + } + _placeholderLabel.Font = _placeholderLabel.Font.WithSize(value.PointSize); + } + else if (_defaultPlaceholderSize != -1) + { + _placeholderLabel.Font = _placeholderLabel.Font.WithSize(_defaultPlaceholderSize); + } + } } } \ No newline at end of file diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index b81f0434c04c..de12ab5c00df 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,5 +1,7 @@ #nullable enable override Microsoft.Maui.Handlers.SwitchHandler.NeedsContainer.get -> bool +override Microsoft.Maui.Platform.MauiTextView.Font.get -> UIKit.UIFont? +override Microsoft.Maui.Platform.MauiTextView.Font.set -> void static Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContentUnbounded(this Microsoft.Maui.IContentView! contentView, Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Platform.MauiTextField.WillMoveToWindow(UIKit.UIWindow? window) -> void override Microsoft.Maui.Platform.MauiTextView.WillMoveToWindow(UIKit.UIWindow? window) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index b81f0434c04c..de12ab5c00df 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,5 +1,7 @@ #nullable enable override Microsoft.Maui.Handlers.SwitchHandler.NeedsContainer.get -> bool +override Microsoft.Maui.Platform.MauiTextView.Font.get -> UIKit.UIFont? +override Microsoft.Maui.Platform.MauiTextView.Font.set -> void static Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContentUnbounded(this Microsoft.Maui.IContentView! contentView, Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Platform.MauiTextField.WillMoveToWindow(UIKit.UIWindow? window) -> void override Microsoft.Maui.Platform.MauiTextView.WillMoveToWindow(UIKit.UIWindow? window) -> void diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs index c5b72ac48b4e..eda5aef345ef 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs @@ -12,6 +12,26 @@ namespace Microsoft.Maui.DeviceTests { public partial class EditorHandlerTests { +#if IOS + [Fact(DisplayName = "Placeholder Size is the same as control")] + public async Task PlaceholderFontHasTheSameSize() + { + var sizeFont = 22; + var editor = new EditorStub() + { + Text = "Text", + Font = Font.SystemFontOfSize(sizeFont) + }; + + var nativePlaceholderSize = await GetValueAsync(editor, handler => + { + return GetNativePlaceholder(handler).Font.PointSize; + }); + + Assert.True(nativePlaceholderSize == sizeFont); + } +#endif + [Fact(DisplayName = "Placeholder Toggles Correctly When Text Changes")] public async Task PlaceholderTogglesCorrectlyWhenTextChanges() {