Closed
Labels
area-controls-buttonButton, ImageButtonarea-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterfixed-in-8.0.0-preview.1.7762Look for this fix in 8.0.0-preview.1.7762!platform/iost/bugSomething isn't working
Milestone
Description
Description
Button is not sized to account for CharacterSpacing on iOS and MacCatalyst.
Steps to Reproduce
- Create a new .NET MAUI app
- Modify the button on MainPage.xaml to include CharacterSpacing="1"
- Run the application on iOS or MacCatalyst
Link to public reproduction project repository
https://github.com/tdeborde2/MauiCharacterSpacing
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, macOS
Affected platform versions
iOS 15.5, MacOS 12.6
Did you find any workaround?
I was able to workaround the issue with a custom button control.
This can be found in the repro project.
public class CustomButton : Button
{
bool _sizeAllocated;
double _oldCharacterSpacing;
protected override void OnSizeAllocated(double width, double height)
{
if(!_sizeAllocated && WidthRequest == -1 && HorizontalOptions.Alignment != LayoutAlignment.Fill)
{
_sizeAllocated = true;
this.WidthRequest = width + ((Text.Length - 1) * CharacterSpacing);
return;
}
base.OnSizeAllocated(width, height);
}
protected override void OnPropertyChanging([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanging(propertyName);
if(propertyName == "Text")
{
if (_sizeAllocated)
{
WidthRequest = -1;
_sizeAllocated = false;
}
}
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (_sizeAllocated && HorizontalOptions.Alignment != LayoutAlignment.Fill)
{
if (propertyName == "CharacterSpacing")
{
if (CharacterSpacing < _oldCharacterSpacing)
{
WidthRequest = Width - ((Text.Length - 1) * (_oldCharacterSpacing - CharacterSpacing));
}
if (CharacterSpacing > _oldCharacterSpacing)
{
WidthRequest = Width + ((Text.Length - 1) * (CharacterSpacing - _oldCharacterSpacing));
}
}
}
_oldCharacterSpacing = CharacterSpacing;
}
}Relevant log output
No response
Reacted by riccardominato
Metadata
Metadata
Assignees
Labels
area-controls-buttonButton, ImageButtonarea-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterfixed-in-8.0.0-preview.1.7762Look for this fix in 8.0.0-preview.1.7762!platform/iost/bugSomething isn't working




Activity
hartez commentedon Feb 3, 2023
I think we're handling attributed text in the UIButtons incorrectly; instead of grabbing the internal UILabel and updating it, we should probably be using
SetAttributedTitle(). I'd bet if we used that method the UIButtons would update their layouts appropriately.[iOS] Fix sizing of button when using CharacterSpacing (#13250) Fixes #…
Merge net8.0 into release/8.0.1xx-preview1 (#13441)
[iOS] Fix sizing of button when using CharacterSpacing (dotnet#13250) F…