Skip to content

Commit

Permalink
[iOS] Fix sizing of button when using CharacterSpacing (#13250) Fixes #…
Browse files Browse the repository at this point in the history
…10293

* [iOS] Set the attributed title on the button and not the inner label

* Just small cleanup on this file

* Reinstate test fix

---------

Co-authored-by: E.Z. Hart <[email protected]>
  • Loading branch information
rmarinho and hartez authored Feb 15, 2023
1 parent 7847d2b commit 5cbb27e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/Core/src/Platform/iOS/ButtonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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)
Expand Down Expand Up @@ -79,7 +80,5 @@ public static void UpdatePadding(this UIButton platformButton, Thickness padding
#pragma warning restore CA1422 // Validate platform compatibility
#pragma warning restore CA1416
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 5cbb27e

Please sign in to comment.