Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting class when calling createLabel

I'm using Titanium Studio and Titanium SDK. In this case I'm developing for Android but I have an installation on OSX too.

When using Alloy, I can specify

<Label class="header" id="someId">Week 50</Label>

and then specify the colors,fonts etc in the TSS file like this

".header": {
  color: "blue"
}

However when I use the SDK version:

var l = Ti.UI.createLabel({class:"header", text:"sometext"});

The color from the TSS file isnt picked up???

What am I doing wrong. Isn't 'class' a valid property? (I cant seem to find it in the docs).

like image 954
Peter Andersson Avatar asked May 22 '26 16:05

Peter Andersson


1 Answers

Alloy style are applied automatically to views created through xml. If you want to keep that effect while you are creating objects inside controller you have to use $.UI.create() method instead of Titanium API. In your case your code will look like this:

var l = $.UI.create('Label', {
   title: "sometext",
   classes: ["header"],
});

For more read Dynamic Styles guide. It's not very well documented and some parts of it were unclear for me when I read it but it's good starting point to experiment with the code and learn Alloy behaviour.

like image 77
daniula Avatar answered May 25 '26 11:05

daniula



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!