Skip to content

Instantly share code, notes, and snippets.

@alanleard
Created December 12, 2012 19:09
Show Gist options
  • Save alanleard/4270630 to your computer and use it in GitHub Desktop.
Save alanleard/4270630 to your computer and use it in GitHub Desktop.
mimic iOS switch
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