TONY0922のブログ

学んだことを適当に記録していくブログです。主にRuby, Java, PHPで仕事してます。更新頻度はそんなに高くないので、ご了承下さい。

Titanium MobileのAlloyでControllerで作成したViewにtssの定義を適応させる。

Titanium SDK:3.2.0
Alloy:1.3.0

Controllerで作成したViewはそのままだと
tssで定義したclassを当てはめることができないので、
Dynamic Styleを使うと良い。

index.tss

// Button全てに以下の定義が適用。
"Button" : {
	backgroundColor : "black"
}
".buttonEnabled" : {
	opacity : 1.0,
	touchEnabled : true
}
".buttonSize" : {
	width : "50dp",
	height : "50dp" 
}

index.js

var button = Ti.UI.createButton();
var style = $.createStyle({
	apiName : "Button" // tssの「Button」を指定。
	classes : ["buttonEnabled", "buttonSize"] // 複数のClassを指定。
}); 

button.applyProperties(style); // tssのクラスが適用される。

【参考URL】
http://docs.appcelerator.com/titanium/3.0/#!/guide/Dynamic_Styles