开发者

Uilabel effect like in games

开发者 https://www.devze.com 2022-12-25 09:38 出处:网络
Does anyone know how to make a UILabel appear letter by letter like 开发者_StackOverflowyou can see in some games or other.

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

精彩评论

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