Is there a way to add padding to a label using a custom renderer? I know you can cheat by adding a content view around the label and adding padding to the content view; but I want to keep the UI cleaner and not have to add an extra element.
Just to be clear, I don't want a margin - in other words, if I add a background color to the label, you should see padding between the text and the background of the label, like this:
Have you tried something like this:
namespace CustomFinder.iOS.Renderers
{
public class DataLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
if (Control == null)
{
SetNativeControl(new TagUiLabel());
}
base.OnElementChanged(e);
}
}
public class TagUiLabel : UILabel
{
private UIEdgeInsets EdgeInsets { get; set; }
public TagUiLabel()
{
EdgeInsets = new UIEdgeInsets(0, 3, 0, 3);
}
public override void DrawText(CoreGraphics.CGRect rect)
{
base.DrawText(EdgeInsets.InsetRect(rect));
}
}
}
I have this from here haven't tried it yet.