Can I use one label set more different style?

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

Hello everyone~

I have a question.

Can I use one createLabel to set two or more different style , color or fontSize?

is it possible to reach?

var lb = Ti.UI.createLabel({
        text : "here have much text, but I want to set different color and size on 'different'  text.",
        width : 102,
        height : 30,
        top : 100,
        left : 10,
        font : {
            fontSize : '20',
        },
    color: "#ccc"
    });
win.add(lb);
Suppose I have to set more different color or size in a long text.

is it have to set different createLabel to reach all the same?

thank you very much.

— asked 9 months ago by Chang YuanYu
2 Comments
  • No, the same style applies for whole text

    you have long text and wanna apply different style then you can do string manipulations with label text and can make nested labels and can give your required string length to your custom labels

    — commented 9 months ago by Muhammad Adnan

  • thank you

    — commented 9 months ago by Chang YuanYu

4 Answers

//under event 
lb.color='white'; // to change label color
lb.font = { fontSize : '17', }; // to change font size

— answered 9 months ago by kim huat
answer permalink
1 Comment
  • sorry, I meaning specific text in same label is different color or font Size.

    — commented 9 months ago by Chang YuanYu

You can also use a WebView to present a long block of formatted text. It really depends on your situation.

No, the same style applies for whole text

you have long text and wanna apply different style then you can do string manipulations with label text and can make nested labels and can give your required string length to your custom labels

— answered 9 months ago by Muhammad Adnan
answer permalink
1 Comment
  • I would be curious to see exactly how you would do this. How would you keep the text flowing? In other words, how would you know exactly where to place the labels if your sample text looked like this:

    Tempor amet pellentesque tristique

    pellentesque? Mus odio ultrices

    adipiscing! Tortor facilisis, a porttitor

    How would you know the x,y position of the bold "odio" label, or the italic "facilisis" label? If you have a specific technique, I would be very interested to see it.

    — commented 9 months ago by Jason Priebe

Your Answer

Think you can help? Login to answer this question!