Skip to content
Closed
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
4 changes: 4 additions & 0 deletions src/Controls/src/Core/Button/Button.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ private static void MapPadding(IButtonHandler handler, Button button)
public static void MapText(IButtonHandler handler, Button button)
{
handler.PlatformView?.UpdateText(button);

// Update all of the attributed text formatting properties
Comment thread
kubaflo marked this conversation as resolved.
var fontManager = handler.GetRequiredService<IFontManager>();
handler.PlatformView?.UpdateAttributedTitle(fontManager, button);
}

internal static void MapBorderWidth(IButtonHandler handler, Button button)
Expand Down
12 changes: 12 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18832.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue18832"
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
<VerticalStackLayout>
<Label Text="Button: "/>
<Button AutomationId="button" Text="Hello, World!" CharacterSpacing="10" FontSize="30" FontFamily="OpenSansRegular" TextColor="DarkBlue"/>
<Label Text="Label: "/>
<Label AutomationId="label" Text="Hello, World!" CharacterSpacing="10" FontSize="30" FontFamily="OpenSansRegular"/>
</VerticalStackLayout>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18832.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 18832, "[iOS] Button CharacterSpacing makes FontSize fixed and large", PlatformAffected.iOS)]
public partial class Issue18832 : ContentPage
{
public Issue18832()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue18832 : _IssuesUITest
{
public override string Issue => "[iOS] Button CharacterSpacing makes FontSize fixed and large";

public Issue18832(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Button)]
public void SizesOfBothTextsShouldHaveTheSameAndCharacterSpacing()
{
_ = App.WaitForElement("button");

// The test passes if both "Hello, World!" texts are of the same size
// and have the same character spacing
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions src/Core/src/Handlers/Button/ButtonHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public static void MapText(IButtonHandler handler, IText button)
handler.PlatformView?.UpdateText(button);

// Any text update requires that we update any attributed string formatting
MapFormatting(handler, button);
var fontManager = handler.GetRequiredService<IFontManager>();
handler.PlatformView?.UpdateAttributedTitle(fontManager, button);
}

public static void MapTextColor(IButtonHandler handler, ITextStyle button)
Expand All @@ -116,11 +117,17 @@ public static void MapTextColor(IButtonHandler handler, ITextStyle button)
{
handler.PlatformView?.UpdateTextColor(button);
}

var fontManager = handler.GetRequiredService<IFontManager>();
handler.PlatformView?.UpdateAttributedTitle(fontManager, button!);
}

public static void MapCharacterSpacing(IButtonHandler handler, ITextStyle button)
{
handler.PlatformView?.UpdateCharacterSpacing(button);

Comment on lines 123 to +128
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The call to UpdateCharacterSpacing on line 127 is now redundant because UpdateAttributedTitle on line 130 handles character spacing internally. This duplicate call may result in character spacing being applied twice, potentially causing incorrect rendering. Consider removing line 127.

Suggested change
handler.PlatformView?.UpdateCharacterSpacing(button);

Copilot uses AI. Check for mistakes.
var fontManager = handler.GetRequiredService<IFontManager>();
handler.PlatformView?.UpdateAttributedTitle(fontManager, button);
}

public static void MapPadding(IButtonHandler handler, IButton button)
Expand All @@ -133,12 +140,14 @@ public static void MapFont(IButtonHandler handler, ITextStyle button)
var fontManager = handler.GetRequiredService<IFontManager>();

handler.PlatformView?.UpdateFont(button, fontManager);

handler.PlatformView?.UpdateAttributedTitle(fontManager, button);
}

public static void MapFormatting(IButtonHandler handler, IText button)
{
// Update all of the attributed text formatting properties
handler.PlatformView?.UpdateCharacterSpacing(button);
var fontManager = handler.GetRequiredService<IFontManager>();
handler.PlatformView?.UpdateAttributedTitle(fontManager, button);
}

public static void MapImageSource(IButtonHandler handler, IImage image) =>
Expand Down
28 changes: 28 additions & 0 deletions src/Core/src/Platform/iOS/ButtonExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Foundation;
using UIKit;

namespace Microsoft.Maui.Platform
Expand Down Expand Up @@ -112,5 +113,32 @@ internal static void UpdateContentEdgeInsets(this UIButton platformButton, Thick
#pragma warning restore CA1422 // Validate platform compatibility
#pragma warning restore CA1416
}

internal static void UpdateAttributedTitle(this UIButton platformButton, IFontManager fontManager, ITextStyle textStyle)
{
if(platformButton.CurrentTitle == null)
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

Missing space after 'if' keyword. Should be 'if (' instead of 'if('.

Suggested change
if(platformButton.CurrentTitle == null)
if (platformButton.CurrentTitle == null)

Copilot uses AI. Check for mistakes.
{
return;
}

// Any text update requires that we update any attributed string formatting
var uiFontAttribute = fontManager.GetFont(textStyle.Font, UIFont.ButtonFontSize);
var attributedString = new NSMutableAttributedString(new NSAttributedString(platformButton.CurrentTitle));

// Update font family & size
attributedString.AddAttribute(UIStringAttributeKey.Font, uiFontAttribute, new NSRange(0, attributedString.Length));

//Update UpdateCharacterSpacing
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

Comment contains typo with duplicated word "Update". Should be "Update CharacterSpacing" instead of "Update UpdateCharacterSpacing".

Suggested change
//Update UpdateCharacterSpacing
// Update CharacterSpacing

Copilot uses AI. Check for mistakes.
if (textStyle.CharacterSpacing != 0)
{
attributedString = attributedString.WithCharacterSpacing(textStyle.CharacterSpacing);
}

//Update Text Color
Comment on lines +131 to +137
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

Comment style inconsistency. Use double-slash comment syntax with a space after the slashes, like "// Update Text Color" to match the project's code style.

Suggested change
//Update UpdateCharacterSpacing
if (textStyle.CharacterSpacing != 0)
{
attributedString = attributedString.WithCharacterSpacing(textStyle.CharacterSpacing);
}
//Update Text Color
// Update UpdateCharacterSpacing
if (textStyle.CharacterSpacing != 0)
{
attributedString = attributedString.WithCharacterSpacing(textStyle.CharacterSpacing);
}
// Update Text Color

Copilot uses AI. Check for mistakes.
if (textStyle.TextColor != null)
attributedString = attributedString?.WithTextColor(textStyle.TextColor);

platformButton.SetAttributedTitle(attributedString, UIControlState.Normal);
}
}
}
Loading