c# – 在Xamarin.iOS中使用填充的UILabel?
发布时间:2020-12-15 03:43:53 所属栏目:百科 来源:网络整理
导读:我正在尝试在我的Xamarin.iOS应用程序中创建一个带填充的UILabel.本机Objective-C应用程序中最流行的解决方案是覆盖drawTextInRect: - (void)drawTextInRect:(CGRect)rect { UIEdgeInsets insets = {0,5,5}; return [super drawTextInRect:UIEdgeInsetsInse
我正在尝试在我的Xamarin.iOS应用程序中创建一个带填充的UILabel.本机Objective-C应用程序中最流行的解决方案是覆盖drawTextInRect:
- (void)drawTextInRect:(CGRect)rect { UIEdgeInsets insets = {0,5,5}; return [super drawTextInRect:UIEdgeInsetsInsetRect(rect,insets)]; } 这看起来很简单,我无法弄清楚如何将其转换为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); } } 这似乎会移动标签的文本,但它不会调整标签的大小. 我认为主要问题是我找不到Xamarin等效的UIEdgeInsetsInsetRect. 有什么建议? 解决方法
ObjC函数UIEdgeInsetsInsetRect的C#等价物是名为InsetRect的UIEdgeInsets的实例方法,它与您的RectangleF计算(这可能是您的问题)不同.
要使用它,您可以: public override void DrawText(RectangleF rect) { base.DrawText (Insets.InsetRect (rect)); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |