morcutt morcutt - 1 year ago 422
iOS Question

Animating UILabel Font Size Change

I am currently making an application that uses a custom View Controller container. Multiple views are on the screen at one time and when one is tapped, the selected view controller animates to full screen. In doing so, the selected view controllers subviews scale as well (frame, font size, etc.) Though, UILabel's font property is not animatable leading to issues. I have tried multiple solutions but all flat out suck.

The solutions I have tried are:

  1. Take a screenshot of the larger view and animating the change (similar to how Flipboard does)

  2. Animate by using the transform property

  3. Zooming out a UIScrollView and zooming it in when brought to full screen.

  4. Setting adjustsFontSizeToFitWidth to YES and setting the fontSize prior to animation

One has been the best solution so far but I am not satisfied with it.

I'm looking for other suggestions if anyone has any or a UILabel substitue that animates smoothly using [UIView animate..].

Here is a good example that is similar to what I would like my UILabel to do:

EDIT: This code works

// Load View

self.label = [[UILabel alloc] init];
self.label.text = @"TEXT";
self.label.font = [UIFont boldSystemFontOfSize:20.0];
self.label.backgroundColor = [UIColor clearColor];

[self.label sizeToFit];

[self.view addSubview:self.label];

// Animation

self.label.font = [UIFont boldSystemFontOfSize:80.0];
self.label.transform = CGAffineTransformScale(self.label.transform, .25, .25);
[self.label sizeToFit];

[UIView animateWithDuration:1.0 animations:^{
self.label.transform = CGAffineTransformScale(self.label.transform, 4.0, 4.0); =;
} completion:^(BOOL finished) {

self.label.font = [UIFont boldSystemFontOfSize:80.0];
self.label.transform = CGAffineTransformScale(self.label.transform, 1.0, 1.0);

[self.label sizeToFit];


Answer Source

You can change the size and font of your UILabel with animation like bellow .. here I just put the example of how to change the font of UILabel with transform Animation ..

    yourLabel.font = [UIFont boldSystemFontOfSize:35]; // set font size which you want instead of 35
    yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 0.35, 0.35); 
    [UIView animateWithDuration:1.0 animations:^{
        yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 5, 5);

I hope this helpful to you..