Skip to content

Commit 7b83b49

Browse files
committed
Fix iOS Label being truncated when using Padding
1 parent 5fc2590 commit 7b83b49

File tree

7 files changed

+75
-6
lines changed

7 files changed

+75
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue28180"
5+
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
6+
<ScrollView>
7+
<VerticalStackLayout
8+
Padding="30,0"
9+
Spacing="25">
10+
11+
<Label
12+
x:Name="LongTextLabel"
13+
AutomationId="LongTextLabel"
14+
Padding = "50"
15+
Text="Welcome to this longer text in a Label that should display it's complete contents, but doesn't really do so when it has Padding applied on IOS."
16+
FontSize="32"
17+
HorizontalOptions="Center"
18+
SemanticProperties.HeadingLevel="Level1" />
19+
20+
<Button
21+
x:Name="ToggleBtn"
22+
Text="Click me"
23+
SemanticProperties.Hint="Toggles longer and shorter text for the second label"
24+
Clicked="OnToggleClicked"
25+
HorizontalOptions="Fill" />
26+
</VerticalStackLayout>
27+
</ScrollView>
28+
</ContentPage>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 28180, "Labels with Padding are truncated on iOS", PlatformAffected.iOS | PlatformAffected.macOS)]
4+
public partial class Issue28180 : ContentPage
5+
{
6+
public Issue28180()
7+
{
8+
InitializeComponent();
9+
}
10+
11+
private void OnToggleClicked(object sender, EventArgs e)
12+
{
13+
LongTextLabel.Padding = LongTextLabel.Padding == 50 ? 0 : 50;
14+
}
15+
}
50.2 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if IOSUITEST || MACUITEST
2+
3+
using NUnit.Framework;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues;
8+
9+
public class Issue28180 : _IssuesUITest
10+
{
11+
public Issue28180(TestDevice testDevice) : base(testDevice)
12+
{
13+
}
14+
15+
public override string Issue => "Labels with Padding are truncated on iOS";
16+
17+
[Test]
18+
[Category(UITestCategories.Label)]
19+
public void LabelWithPaddingIsNotTruncated()
20+
{
21+
App.WaitForElement("LongTextLabel");
22+
VerifyScreenshot();
23+
}
24+
}
25+
26+
#endif
131 KB
Loading
-30.1 KB
Loading

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ public override void DrawText(RectangleF rect)
4848

4949
RectangleF AlignVertical(RectangleF rect)
5050
{
51-
var frameSize = Frame.Size;
52-
var height = Lines == 1 ? Font.LineHeight : SizeThatFits(frameSize).Height;
51+
var availableSize = rect.Size;
52+
var requiredHeight = Lines == 1 ? Font.LineHeight : base.SizeThatFits(rect.Size).Height;
5353

54-
if (height < frameSize.Height)
54+
if (requiredHeight < availableSize.Height)
5555
{
5656
if (_verticalAlignment == UIControlContentVerticalAlignment.Top)
5757
{
58-
rect.Height = height;
58+
rect.Height = requiredHeight;
5959
}
6060
else if (_verticalAlignment == UIControlContentVerticalAlignment.Bottom)
6161
{
62-
rect = new RectangleF(rect.X, rect.Bottom - height, rect.Width, height);
62+
rect = new RectangleF(rect.X, rect.Bottom - requiredHeight, rect.Width, requiredHeight);
6363
}
6464
}
6565

@@ -74,7 +74,7 @@ public override SizeF SizeThatFits(SizeF size)
7474
var requestedSize = base.SizeThatFits(new SizeF(adjustedWidth, adjustedHeight));
7575

7676
// Let's be sure the label is not larger than the container
77-
return AddInsets(new Size()
77+
return AddInsets(new Size
7878
{
7979
Width = nfloat.Min(requestedSize.Width, size.Width),
8080
Height = nfloat.Min(requestedSize.Height, size.Height),

0 commit comments

Comments
 (0)