Titanium 将样式应用到我的钛合金用户界面
我刚开始使用Appcelerator的钛合金 如何将样式添加到我的控制器/index.js以下是代码:Titanium 将样式应用到我的钛合金用户界面,titanium,titanium-alloy,Titanium,Titanium Alloy,我刚开始使用Appcelerator的钛合金 如何将样式添加到我的控制器/index.js以下是代码: var title = Titanium.UI.createLabel({ title: "My Label", id: "myLabel" }); 我正在styles/index.tss上尝试这个 "#myLabel": { textAlign: "left", right: 15, color: '#000', font: { fontSize:20 }, shad
var title = Titanium.UI.createLabel({
title: "My Label",
id: "myLabel"
});
我正在styles/index.tss上尝试这个
"#myLabel": {
textAlign: "left",
right: 15,
color: '#000',
font: { fontSize:20 },
shadowColor: '#aaa',
shadowOffset: {x:5, y:5},
horizontalWrap: true
}
但不幸的是,它现在起作用了。有人能教我如何将样式添加到我的Tianium UI中吗?Alloy样式自动应用于通过xml创建的视图。如果您想在控制器内创建对象时保持这种效果,您必须使用方法而不是钛API。在您的情况下,您的代码如下所示:
var title = $.UI.create('Label', {
title: "My Label",
id: "myLabel"
});
更多阅读。它没有很好的文档记录,当我阅读它时,它的某些部分对我来说是不清楚的,但这是实验代码和学习合金行为的良好起点。您的问题似乎在create语句中,您应该使用
text
属性而不是title
:
var title = Titanium.UI.createLabel({
text: "My Label",
id: "myLabel"
});
这种方式,你会看到标签,但是样式不会自动应用,所以考虑其中的一个选项:
- 如果可能,请在视图中创建标签:
<Alloy> <View id="content" class="container"> <Label id="myLabel" text="My Label"/> </View> </Alloy>
- 其他解决方案是在代码中应用样式:
$.myLabel.text = "New value";
在这种情况下,您需要在.tss文件中替换var title = Ti.UI.createLabel({ text: "My Label", id: "myLabel" }); var style = $.createStyle({ classes: ['myLabel'] ,apiName: 'Label'}); title.applyProperties(style);
for“#myLabel”:{
“.myLabel”:{
- 简单的解决方案是添加如下所示的类
$.addClass(yourView, "yourClassName");
将您的类添加到
.tss文件中。您的第一个答案是不相关的,因为您可以看到我为标签声明了一个变量标题,其文本属性设置为“我的标签”。其次,我不能只将标签添加到视图中,因为我有一个将自动创建标签的循环。第三,您的上一个解决方案可以只调用index.tss中标签的id,如“#myLabel”:{}你好,艾伦,我认为最后一个解决方案对你来说是完美的,我的意思是你需要替换“#myLabel”:{textAlign:“left”,right:15,color:“#000”,font:{fontSize:20},shadowColor:“#aaa”,shadowOffset:{x:5,y:5},horizontalWrap:true}
对于“.myLabel:{textAlign:{,右:15,颜色:'#000',字体:{fontSize:20},阴影颜色:'#aaa',阴影偏移量:{x:5,y:5},水平包裹:真}
看看我的答案。有$.UI.create()方法,在Appcelerator文档中没有很好的文档记录,但正好适合这个用例。这就是我现在搜索interwebz的原因。样式文档冗长且含糊不清。这节省了我数小时的谷歌搜索时间