Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate UILabel text size increase and decrease

Tags:

ios

iphone

I want to apply animation on UILabel text. I write the code to increase font size in animation block but animation is not applied.

[UIView beginAnimations:nil context:nil/*contextPoint*/];
    monthsOnBoard.font=[UIFont fontWithName:@"digital-7" size:150];
    daysOnBoard.font=[UIFont fontWithName:@"digital-7" size:150];
    hoursOnBoard.font=[UIFont fontWithName:@"digital-7" size:100];
    minutesOnBoard.font=[UIFont fontWithName:@"digital-7" size:100];
    secondsOnBoard.font=[UIFont fontWithName:@"digital-7" size:100];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDelay:0.5];
    [UIView setAnimationDuration:1];
    [UIView setAnimationRepeatCount:4];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView commitAnimations];
like image 920
Idrees Ashraf Avatar asked Dec 21 '22 21:12

Idrees Ashraf


1 Answers

The font of a UIView is not an animatable property. You should use transforms instead.

[UIView beginAnimations:nil context:nil/*contextPoint*/];
monthsOnBoard.transform = CGAffineTransformMakeScale(2.0, 2.0); //increase the size by 2
 //etc etc same procedure for the other labels.
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];

similarly, you can play with the values in CGAffineTransformMakeScale(x, y); - x is the horizontal scale constant and y is the vertical one. Enjoy!!

like image 58
Kaan Dedeoglu Avatar answered Jan 06 '23 06:01

Kaan Dedeoglu