iphone-sdk-3.0uikituilabel

Can font size of UILabel be changed with smooth animation on iPhone?


I want a UILabel to swell slightly when selected like in some game menu screens. To get smooth resizing I presume I should put some change to the label's properties in an animation block.

The obvious thing to try is to change the label.font.pointSize property but that's readonly.

Scaling the label's .transform property with CGAffineTransformationMakeScale() makes the text blurry.

Is there some other way to do this?


Solution

  • Set the font on the UILabel to be the size that you want when it is enlarged. Then scale it down. When you want the label to swell, scale it back up to it's original size.

        messageLabel.font = [UIFont boldSystemFontOfSize:45]; 
        messageLabel.transform = CGAffineTransformScale(messageLabel.transform, 0.25, 0.25); 
        [self.view addSubview:messageLabel]; 
        [UIView animateWithDuration:1.0 animations:^{
            messageLabel.transform = CGAffineTransformScale(messageLabel.transform, 4, 4);
        }];