我是钛金属的新手,正在开关上,我有两个图像“开”和“关”,当我滑动“开”时,应该将其切换为“关”。
这是我要使用的两个图像。

 

我不知道如何使用这些图片。.我唯一能做的就是默认开关

这是编码

var basicSwitch = Ti.UI.createSwitch({
value:true ,// mandatory property for iOS
color: 'white',
left : 40,
top:0,
backgroundColor:'black'
});
cview.add(basicSwitch);

basicSwitch.addEventListener('change',function(e){
Ti.API.info('Switch value: ' + basicSwitch.value);

最佳答案

内置于Slider中的本机不支持自定义图像(iOS上除外)。我建议您将其实现为一个按钮,如果按所需方向滑动该按钮,该按钮会更改。

var switchButton = Ti.UI.createButton({
    image: "/disabledSwitch.png", //exchange for your location
    //Add the dimensions
    title: "OFF" });

switchButton.addEventListener ('swipe', function() {
    if (e.direction == "right" && e.source.title == "OFF" {
        //Enable the "switch"
        switchButton.setImage("Your active image");
        switchButton.setTitle("ON");
        //Set your desired actions
    } else if (.direction == "left" && e.source.title == "ON" {
        //Disable the "switch"
        switchButton.setImage("Your inactive image");
        switchButton.setTitle("OFF");
        //Set your desired actions
    } });

cview.add(switchButton);


您还可以另外添加一个点击监听器。

关于javascript - 钛如何在开关中使用图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26480799/

10-11 22:51
查看更多