开发者

Uilabel effect like in games

Does anyone know how to make a UILabel appear letter by letter like 开发者_StackOverflowyou can see in some games or other.

thanks


Set up an NSTimer to set the text property of the UILabel.

-(void) revealTimer:(NSTimer *)inTimer {
 if ( ++mIndex < [mFullString length] ) {
  mLabel.text = [mFullString substringToIndex:mIndex];
 } else {
  mLabel.text = mFullString;
  [inTimer invalidate];
 }
}

start it up with something like this:

-(void) revealString:(NSString *)inString {
 mIndex = 0;
 mLabel.text = "";
 mFullString = [inString retain];
 [NSTimer scheduledTimerWithTimeInterval:0.125 target:self selector:@selector(revealTimer:) userInfo:nil repeats:YES];
}

be sure not to leak mFullString as the above does, and store the timer if you may need to invalidate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜