Label background rectangle with padding

You must Login before you can answer or comment on any questions.

Dear people,

I want to make custom tableviewrows with styled labels.

The label needs a black background with fuiven padding on the left, right, top and bottom. When i set the backgroundColor to black it's almost what i need but i cant set the padding. With à background image image in getting it perfect only im getting draw errors on the label.

I also tried to detect the width of the label and setting a view with a black background but it takes to long to detect the width so it's getting jumpy!

Are there some better solutions?

— asked 12 months ago by Blaat Orx
0 Comments

3 Answers

Sadly as far as I know, label in titanium don't have padding.

The solution is to create a view with the height and width of your label, put the background to the view, and add the label to the view.

On the label you set the padding with top, left, right, bottom.

And this should do the tricks

I understand but when im calculating the width of the label imediately it gives me "0" an d then i have to set an interval to get it right.

The ugly thig about this that you can see its calculating, is there something to fix that?

Thanks again!

maybe you can fix this errors on my labels (only with the backgroundImage on):

Thu Jun 14 17:20:28 [3813] <Error>: CGContextConcatCTM: invalid context 0x0
Thu Jun 14 17:20:28 [3813] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
Thu Jun 14 17:20:28 [3813] <Error>: CGContextDrawImage: invalid context 0x0
Thu Jun 14 17:20:28 [3813] <Error>: CGBitmapContextCreateImage: invalid context 0x0
It's working fine except those error messages...

Code for my label:

var programLabel = Ti.UI.createLabel({
                        font:{fontSize:14, fontFamily:'Custom', fontWeight:'medium'},
                        text:xmlArray[i][1].toUpperCase(),
                        color:'#fff',
                        left:3,
                        height:17,
                        top:3,
                        backgroundImage:'images/tableview/label-stretch.png',
                        backgroundPaddingTop:3,
                        backgroundPaddingLeft:3,
                        backgroundPaddingRight:4,
                        backgroundPaddingBottom:-3,                 
                        arrID:i,
                        layout:'horizontal'
                    });

Your Answer

Think you can help? Login to answer this question!