Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Padding in label???

Hi i have a label like this

var label = Ti.UI.createLabel({
          text: 'TITANIUM',
          font:{fontWeight:'bold',fontSize:14},
          left:60,
          color:'white',
        borderRadius:8,
        backgroundGradient:{type:'linear',
        colors:['#101010','#555555'],
        startPoint:{x:0,y:0},
        endPoint:{x:2,y:60},
        backFillStart:false},
        height:30,
        width:150,
        paddingLeft:5
        });

i want to add left padding…How can i do it.??(for iphone)

— asked October 19th 2011 by mathew orleans
  • label
0 Comments

4 Answers

  • The answer is easy and works very well. Instead of putting the label in a view. Put the label in another label. A label IS a view anyway but it has a really useful characteristic, it tries to stay as small as possible and so it will expand to fit the objects within it, so don't give the outer label any height or width. If you put a label in a label and then put top, bottom, left and right values on the inner label, you will have your padding. You can put all sorts of things in a label , (I have even used it to contain button bars!!)

    — answered October 10th 2012 by James Kenny
    permalink
    1 Comment
    • Hey, I tried this solutions but didn't work on Android. Any idea why?

      — commented May 16th 2015 by Abhishek Upadhyay
  • Not sure if there is a better way, but I've created a view and then put the label int he view and used left, right, top, bottom of the label to act as a padding within the view.

    I also think the marketplace has a styleable label. https://marketplace.appcelerator.com/apps/790

    — answered October 19th 2011 by Frank A
    permalink
    0 Comments
  • I found the quickest way to add some extra spacing below a padding a label was to add carriage returns.

    Using the example as basis:

    
    var label = Ti.UI.createLabel({
            text: 'TITANIUM' + '\n\n\n'
    });
    
    — answered September 4th 2012 by Michael Breuer
    permalink
    0 Comments
  • use

    Lable.backgroundPaddingLeft :5

    it will extend the background color or image to left. it works only on iPhone

    — answered September 19th 2012 by Abrar Sair
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.