在Titanium Appcelerator中区分iPhone和iPad

时间:2013-04-28 06:18:43

标签: appcelerator titanium-mobile appcelerator-mobile

我是跨平台Titanium SDK和Alloy MVC框架的新手。

我在index.xml中创建了一个按钮,如下所示:

 <Alloy>
    <Button id="button">Click Me</Button>
</Alloy>

但现在我想知道如何在iPhone上显示“Click Me”标题,并在iPad上显示标题为“提交”。

我需要在哪里写出条件?在index.xml,index.js或index.tss?

1 个答案:

答案 0 :(得分:7)

您可以通过以下几种方式执行此操作:index.xml文件,如下所示:

<Alloy>
    <Button formFactor="handheld" id="button">Click Me</Button>
    <Button formFactor="tablet" id="button">Submit</Button>
</Alloy>

或者在index.js中这样:

if(Alloy.isHandheld) {
    $.button.title = "Click Me";
}

if(Alloy.isTablet) {
    $.button.title = "Submit";
}

或者在样式文件中,index.tss如下:

"#button[formFactor=handheld]" : { 
    title : "Click Me"
},

"#button[formFactor=tablet]" : { 
    title : "Submit"
}
相关问题