Yama
Yama

Reputation: 2649

Objective C : Animating UILabel at some specific index

I am working on an Application, where I have to display a Sentence in a UILabel and after some seconds the first word should animate with zoom in and out then the second word and so on until the whole sentence gets completed.

Now the thing is I am getting plenty of tutorials on animating the whole UILabel but I am unable to animate a single word at a particular index.

Upvotes: 0

Views: 291

Answers (2)

Yama
Yama

Reputation: 2649

I stored the entire story in string form and then using "componentsSeparatedByString" function created nsmutable array (using space as separator) from which i created uilabel for each and in that way i got all the words for a sentence/story in different labels where i highlighted the required labels.

Upvotes: 1

BhushanVU
BhushanVU

Reputation: 3455

Try this code...

- (void)animateLableString:(NSString*)text delayInterval:(NSTimeInterval)delay
     {    
        [self.label setText:@""];

     for (int i=0; i<text.length; i++)
     {
       dispatch_async(dispatch_get_main_queue(),
        ^{
            [self.label setText:[NSString stringWithFormat:@"%@%C", self.label.text, [text 
             characterAtIndex:i]]];
             label.font = [UIFont boldSystemFontOfSize:45]; 
             label.transform = CGAffineTransformScale(messageLabel.transform, 0.25, 0.25); 

           [UIView animateWithDuration:1.0 animations:^{
            label.transform = CGAffineTransformScale(messageLabel.transform, 4, 4);
            }];
            });

            [NSThread sleepForTimeInterval:delay];
        }
    }

Call it inside where you want to start animation...

-(void)someMethod
{

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
    ^{
        [self animateLableString:@"This is animating" delayInterval:0.5];
    });
}

Upvotes: 0

Related Questions