Created
December 12, 2012 19:09
-
-
Save alanleard/4270630 to your computer and use it in GitHub Desktop.
mimic iOS switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow(); | |
var switchContainer = Ti.UI.createView({ | |
width:100, | |
height:40, | |
borderRadius:10, | |
backgroundColor:'gray' | |
}); | |
var switchLabelYes = Ti.UI.createLabel({ | |
text:'Yes', | |
left:5, | |
textAlignment:'left', | |
width:'size', | |
color:'white' | |
}); | |
var switchLabelNo = Ti.UI.createLabel({ | |
text:'No', | |
right:5, | |
textAlignment:'right', | |
width:'size', | |
color:'white' | |
}); | |
var switchBtn = Ti.UI.createView({ | |
width:50, | |
height:40, | |
left:0, | |
borderRadius:10, | |
backgroundColor:'blue' | |
}); | |
switchContainer.add(switchLabelYes, switchLabelNo, switchBtn); | |
win.add(switchContainer); | |
switchBtn.addEventListener('click', function(){ | |
if(switchBtn.left == 0){ | |
switchBtn.animate({left:50, duration:500}, function(){ | |
switchBtn.left = 50; | |
alert('Yes') | |
}); | |
} else { | |
switchBtn.animate({left:0, duration:500}, function(){ | |
switchBtn.left = 0 | |
alert('No') | |
}); | |
} | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment