2013-04-28 31 views
3

我是跨平臺Titanium SDK和Alloy MVC框架的新手。在Titaninum Appcelerator中區分iPhone和iPad

我創建了一個按鈕內INDEX.XML這樣的:

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

但現在我想知道如何顯示的標題是「點擊我」在iPhone上時,並顯示標題「提交」時在iPad上。

我需要在哪裏編寫條件?在index.xml中,index.js或index.tss?

回答

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" 
} 
+0

非常感謝。幫了我很多。 – SSS 2014-10-02 03:56:35