繁体   English   中英

钛如何在开关中使用图像

[英]Titanium how to use images in switch

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

关闭上

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

这是编码

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM