我想为我的 Titanium 应用程序创建一个样式表。我没有使用 Alloy 框架,那么我该如何使用 app.tss?我需要将它存储在哪个目录中?
谢谢
我想为我的 Titanium 应用程序创建一个样式表。我没有使用 Alloy 框架,那么我该如何使用 app.tss?我需要将它存储在哪个目录中?
谢谢
你不能。
.tss 文件是 Alloy 带来的功能。但是,如果您想使用自定义样式,您可以查看applyProperties方法。
你也许可以做一些这样的解决方法:
http://tifiddle.com/e9b87d0f3debd5e4a7bab3beb03dbddd
// Create window object
var win = Ti.UI.createWindow(),
label = Ti.UI.createLabel();
// Create or import properties
var properties = {
window: {
backgroundColor: "#1DB7FF"
},
label: {
text: "I Love Titanium",
color: "#FFFFFF"
}
};
// Apply properties
win.applyProperties(properties.window);
label.applyProperties(properties.label);
// Build views and launch
win.add(label);
win.open();
您可以使用 CommonJS 来实现这一点
资源/styles.js
exports.Window = {
backgroundColor: 'blue',
backgroundImage: '/images/homebg.png',
exitOnClose: true
};
exports.Label = {
color: 'gray',
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
backgroundColor: 'transparent',
font: {
fontFamily:'Helvetica',
fontSize: '12dp',
fontStyle: 'normal',
fontWeight: 'normal'
}
};
用法
var homeWin = Ti.UI.createWindow(require('styles').Window);
你也可以参考这个