diff --git a/src/Core/src/Platform/iOS/ButtonExtensions.cs b/src/Core/src/Platform/iOS/ButtonExtensions.cs index ed8a3468ad77..989c61b03b10 100644 --- a/src/Core/src/Platform/iOS/ButtonExtensions.cs +++ b/src/Core/src/Platform/iOS/ButtonExtensions.cs @@ -9,7 +9,7 @@ public static class ButtonExtensions public static void UpdateStrokeColor(this UIButton platformButton, IButtonStroke buttonStroke) { - if (buttonStroke.StrokeColor != null) + if (buttonStroke.StrokeColor is not null) platformButton.Layer.BorderColor = buttonStroke.StrokeColor.ToCGColor(); } @@ -30,21 +30,22 @@ public static void UpdateText(this UIButton platformButton, IText button) => public static void UpdateTextColor(this UIButton platformButton, ITextStyle button) { - if (button.TextColor != null) - { - var color = button.TextColor.ToPlatform(); + if (button.TextColor is null) + return; - platformButton.SetTitleColor(color, UIControlState.Normal); - platformButton.SetTitleColor(color, UIControlState.Highlighted); - platformButton.SetTitleColor(color, UIControlState.Disabled); + var color = button.TextColor.ToPlatform(); - platformButton.TintColor = color; - } + platformButton.SetTitleColor(color, UIControlState.Normal); + platformButton.SetTitleColor(color, UIControlState.Highlighted); + platformButton.SetTitleColor(color, UIControlState.Disabled); + + platformButton.TintColor = color; } public static void UpdateCharacterSpacing(this UIButton platformButton, ITextStyle textStyle) { - platformButton.TitleLabel.UpdateCharacterSpacing(textStyle); + var attributedText = platformButton?.TitleLabel.AttributedText?.WithCharacterSpacing(textStyle.CharacterSpacing); + platformButton?.SetAttributedTitle(attributedText, UIControlState.Normal); } public static void UpdateFont(this UIButton platformButton, ITextStyle textStyle, IFontManager fontManager) @@ -79,7 +80,5 @@ public static void UpdatePadding(this UIButton platformButton, Thickness padding #pragma warning restore CA1422 // Validate platform compatibility #pragma warning restore CA1416 } - - } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs index 4faa5ca36d2e..103ab3faffac 100644 --- a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs @@ -86,7 +86,7 @@ double GetNativeCharacterSpacing(ButtonHandler buttonHandler) { var button = GetNativeButton(buttonHandler); - var attributedText = button.TitleLabel.AttributedText; + var attributedText = button.GetAttributedTitle(UIControlState.Normal); return attributedText.GetCharacterSpacing(); }