I am trying to create a UILabel with padding in an Xamarin.iOS application. The most popular solution in native Objective-C applications is to override drawTextInRect :
- (void)drawTextInRect:(CGRect)rect { UIEdgeInsets insets = {0, 5, 0, 5}; return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)]; }
Easier, as it seems, I canβt figure out how to translate it to C #. Here is my best hit on it:
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); } }
This seems to move the label text, but it does not resize the label.
I think the main problem is that I cannot find the Xamarin equivalent of UIEdgeInsetsInsetRect .
Any suggestions?
Josh earl
source share