Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fix sizing of button when using CharacterSpacing #13250

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the important change, rest is just cleanup on this file.

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);
rmarinho marked this conversation as resolved.
Show resolved Hide resolved

return attributedText.GetCharacterSpacing();
}
Expand Down