Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在交换机中使用图像_Javascript_Titanium Mobile - Fatal编程技术网

Javascript 如何在交换机中使用图像

Javascript 如何在交换机中使用图像,javascript,titanium-mobile,Javascript,Titanium Mobile,我是钛合金新手,正在研究开关,我有两个图像打开和关闭,当我们滑动打开时,它应该切换到关闭。。 下面是我试图使用的两幅图片 我不知道如何使用这些图像。我唯一能做的就是使用默认的开关 这是编码 var basicSwitch = Ti.UI.createSwitch({ value:true ,// mandatory property for iOS color: 'white', left : 40, top:0, backgroundColor:'black' }); cview.add(

我是钛合金新手,正在研究开关,我有两个图像打开关闭,当我们滑动打开时,它应该切换到关闭。。 下面是我试图使用的两幅图片

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

这是编码

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);

本机内置的滑块不支持自定义图像(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);
您还可以另外添加一个单击侦听器。

谢谢@Robin,添加“背景:'transparent'”将完成切换控制。