我正在设置a的左边插入/边距,UILabel但找不到这样做的方法.标签有一个背景设置,所以只是改变它的起源不会有效.10px左手边左右插入文本是理想的.
我正在尝试UILabel在我的Xamarin.iOS应用程序中创建一个填充.本机Objective-C应用程序中最流行的解决方案是重写drawTextInRect:
- (void)drawTextInRect:(CGRect)rect {
UIEdgeInsets insets = {0, 5, 0, 5};
return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}
Run Code Online (Sandbox Code Playgroud)
这看起来很简单,我无法弄清楚如何将其转换为C#.这是我最好的尝试:
internal class PaddedLabel : UILabel
{
public UIEdgeInsets Insets { get; set; }
public override void DrawText(RectangleF rect)
{
var padded = new RectangleF(rect.X + Insets.Left, rect.Y, rext.Width + Insets.Left + Insets.Right, rect.Height);
base.DrawText(padded);
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎会移动标签的文本,但它不会调整标签的大小.
我认为主要问题是我找不到相应的Xamarin UIEdgeInsetsInsetRect.
有什么建议?