Implementation of spray gun typing animation in iOS

Source: Internet
Author: User

Implementation of spray gun typing animation in iOS

The implementation principle is relatively simple. I will not introduce it too much here.

 

#import ViewController.h@interface ViewController ()@property (weak, nonatomic) IBOutlet UILabel *titleLabel;@property (copy , nonatomic)NSString *contentStr;@end

-(Void) viewDidLoad {[super viewDidLoad]; NSThread * thread = [[NSThread alloc] initWithTarget: self selector: @ selector (animationLabel) object: nil]; [thread start]; self. contentStr = @ the most precious thing in life is life. Life only belongs to one person once. A person's life should be spent like this: When he remembers the past, he will not regret it because of the past, nor be ashamed of being idle. When he dies, he can say: "my whole life and all my energy have been devoted to the most magnificent undertaking in the world-the struggle for the liberation of mankind. "; }

- (void)animationLabel{    for (NSInteger i = 0; i < self.contentStr.length; i++)    {        [self performSelectorOnMainThread:@selector(refreshUIWithContentStr:) withObject:[self.contentStr substringWithRange:NSMakeRange(0, i+1)] waitUntilDone:YES];        [NSThread sleepForTimeInterval:0.3];    }}

- (void)refreshUIWithContentStr:(NSString *)contentStr{    self.titleLabel.text = contentStr;}

 

 

Final effect:

 

 

 



 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.