Skip to content

Instantly share code, notes, and snippets.

@milon120203
Last active April 9, 2018 16:55
Show Gist options
  • Save milon120203/a9a562e1b59a6ea66016ad4f2a887b09 to your computer and use it in GitHub Desktop.
Save milon120203/a9a562e1b59a6ea66016ad4f2a887b09 to your computer and use it in GitHub Desktop.
Auto ScrollView
//Tested with Ti-SDK 7.02.GA
//Works fine
var win=Titanium.UI.createWindow({
backgroundColor:"green"
});
var view= Ti.UI.createView({
height:Ti.UI.SIZE,
width: Ti.UI.SIZE,
top: "50%",
});
var label=Ti.UI.createLabel({
left:10,
text:"A quick brown fox jumps right over a lazy dog",
color : "#000",
font: {
fontSize : 22,
fontWeight : "bold",
fontFamily: 'Helvetica Neue Ultra Light'
},
height:Ti.UI.SIZE,
width: Ti.UI.SIZE,
});
function animateLongText(label) {
// this line calculates the actual width of the long text
var width = label.toImage().width;
//The condition is given to roll the text if its width is more than 300 .Because in IOS width of the screen is approximately equal to 320.You can adjust it according to screen size
if (width >= 300) {
// Now create the animation in order to scroll the text from right to left and repeat will tell to move text no of times.
var animation = Titanium.UI.createAnimation({
left : -250,
duration : 10000,
repeat : 100,
});
// When animation gets completed then set the text left alignment according to your actual width of the screen size
animation.addEventListener('complete', function() {
label.left = 320;
});
label.width = width;
//Calling the animate function of the text
label.animate(animation);
}
};
// Calling the animateLongText method by passing label’s reference
animateLongText(label);
view.add(label);
win.add(view);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment