Label Padding

Is it possible to add padding on a Label? If not, what's a workaround if I want some space between the text and the edge of the label?

Thanks!

Best Answer

Answers

  • MarkMadlangbayanMarkMadlangbayan USUniversity

    Thanks!

  • ChrisChanChrisChan MYMember

    not really work, not all text is left align. it put into grid .:(

  • ThomasBurkhartThomasBurkhart DEMember ✭✭✭✭

    You can add a Frame around the Label. It has Padding properties

  • NMackayNMackay GBInsider, University ✭✭✭✭✭

    The latest pre-release of Forms includes margin support, worth investigating.

    Margins

    Adding margin support is intended to allow users to reduce the overall depth of their layout hierarchies by allowing more complex layouts with fewer wrapping views.
    public Thickness Margin { get; set; }

    http://forums.xamarin.com/discussion/63983/xamarin-forms-2-2-0-pre2-released/p1

  • OnurHazarOnurHazar USUniversity ✭✭

    @LuckyDay Thanks, it works. Do we need to wrap up in <ContentView.Content> ?

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭
    edited September 2016

    @onur.hazar - Whilst using ContentView used to be how this was done (without using a custom renderer anyway), it is now possible to use the Margin property on Label, which is more efficient than wrapping in a ContentView.

  • OnurHazarOnurHazar USUniversity ✭✭

    @JohnHardman Thanks!

  • BhaurajBiradar.9064BhaurajBiradar.9064 USMember ✭✭
    edited November 7

    Try below too,

    internal class DemoLabelRenderer : LabelRenderer
    {
        private UIEdgeInsets EdgeInsets { get; set; }
    
        public override void Draw(CGRect rect)
        {
            EdgeInsets = new UIEdgeInsets(0, 2, 0, 2);
            base.Draw(EdgeInsets.InsetRect(rect));
        }
    }
    
Sign In or Register to comment.