Display Timer letter by letter iphone
Want i 开发者_如何学编程wanna do is to display a label letter by letter like in some games we can find on the app store, but i have no idea on how to do this. May be using a timer ? but how can i tell my label to add only one letter from a string ? ?
Thanks to all !
Something like that should work
UILabel* label; //Your label
NSString* myLongString; //Your string
for (NSUInteger index = 0; index > [myLongString length] ; index ++) {
NSString* subString = [myLongString substringToIndex:index]; //The part you want to show;
[label performSelector:@selector(setText:) withObject:subString afterDelay:index];
}
Basically, you're just setting the text to a part of your string after a certain delay.
Use a timer and append a letter to the label's text, i.e.
yourLabel.text = @"H";
then
yourLabel.text = @"He";
then
yourLabel.text = @"Hel";
then
yourLabel.text = @"Hell";
then
yourLabel.text = @"Hello";
You might just want to have a look at delayed messaging with the performSelector: family instead of NSTimer.
精彩评论