Skip to content

Commit d0c0c98

Browse files
Dhivya-SF4094rmarinho
authored andcommitted
Fixed Label Visibility Issue on macOS and iOS (#28081)
* Fixed Label Display on macOS and IOS When Padding is Applied * Optimized the fix * Added test case * Added Snapshot for android and iOS * Added snapshot for winUI and macOS, updated test sample
1 parent cfeb1bf commit d0c0c98

File tree

7 files changed

+52
-1
lines changed

7 files changed

+52
-1
lines changed
24.2 KB
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 19007, "Incomplete Label Display on macOS and IOS When Padding is Applied", PlatformAffected.iOS)]
4+
public class Issue19007 : ContentPage
5+
{
6+
public Issue19007()
7+
{
8+
var grid = new Grid();
9+
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
10+
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(100) });
11+
12+
var label = new Label
13+
{
14+
Background = Colors.Red,
15+
Text = ".NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating mobile and desktop apps with C# and XAML.",
16+
Padding = new Thickness(20),
17+
AutomationId = "Label"
18+
};
19+
20+
grid.Children.Add(label);
21+
Grid.SetRow(label, 0);
22+
Grid.SetColumn(label, 0);
23+
24+
Content = grid;
25+
}
26+
}
27+
}
16.2 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
public class Issue19007 : _IssuesUITest
7+
{
8+
public Issue19007(TestDevice testDevice) : base(testDevice)
9+
{
10+
}
11+
12+
public override string Issue => "Incomplete Label Display on macOS and IOS When Padding is Applied";
13+
14+
[Test]
15+
[Category(UITestCategories.Label)]
16+
public void LabelWithPadding()
17+
{
18+
App.WaitForElement("Label");
19+
VerifyScreenshot();
20+
}
21+
}
6.24 KB
Loading
43.2 KB
Loading

src/Core/src/Platform/iOS/MauiLabel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ RectangleF AlignVertical(RectangleF rect)
6868

6969
public override SizeF SizeThatFits(SizeF size)
7070
{
71-
var requestedSize = base.SizeThatFits(size);
71+
// Prior to calculating the text size, reduce the padding, and then add the padding back in the AddInsets method.
72+
var adjustedWidth = size.Width - TextInsets.Left - TextInsets.Right;
73+
var adjustedHeight = size.Height - TextInsets.Top - TextInsets.Bottom;
74+
var requestedSize = base.SizeThatFits(new SizeF(adjustedWidth, adjustedHeight));
7275

7376
// Let's be sure the label is not larger than the container
7477
return AddInsets(new Size()

0 commit comments

Comments
 (0)