Skip to content

Instantly share code, notes, and snippets.

@alanleard
Created March 1, 2013 16:28
Show Gist options
  • Save alanleard/5065810 to your computer and use it in GitHub Desktop.
Save alanleard/5065810 to your computer and use it in GitHub Desktop.
Custom slider
var win = Ti.UI.createWindow();
var slider = Ti.UI.createView({
height:28,
width:358,
backgroundImage:'slider.png',
top:0
});
var button = Ti.UI.createView({
height:57,
width:53,
top:0,
backgroundImage:'button.png'
});
var container = Ti.UI.createView({
height:button.height,
width:slider.width+button.width
});
var label = Ti.UI.createLabel({
bottom:5,
color:'white'
});
var value = 0;
container.add(slider)
container.add(button);
win.add(label);
win.add(container);
button.addEventListener('touchmove', function(evt){
var point = button.convertPointToView({ x: evt.x, y: evt.y }, container);
if(point.x>(button.width/2) && point.x<slider.width+(button.width/2)){
button.center = point;
value = point.x-(button.width/2)
label.text=value;
}
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment