相关疑难解决方法(0)

UILabel文字边距

我正在设置a的左边插入/边距,UILabel但找不到这样做的方法.标签有一个背景设置,所以只是改变它的起源不会有效.10px左手边左右插入文本是理想的.

cocoa-touch uikit uilabel ios

307
推荐指数
21
解决办法
26万
查看次数

UILabel在Xamarin.iOS中有填充?

我正在尝试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.

有什么建议?

c# iphone uilabel xamarin.ios ios

10
推荐指数
2
解决办法
9230
查看次数

标签 统计

ios ×2

uilabel ×2

c# ×1

cocoa-touch ×1

iphone ×1

uikit ×1

xamarin.ios ×1