可以在iPhone上通过流畅的动画更改UILabel的字体大小吗?

可以在iPhone上通过流畅的动画更改UILabel的字体大小吗?

问题描述:

我希望 UILabel 在某些游戏菜单屏幕中被选中时会略微膨胀.为了获得平滑的大小调整,我想我应该在动画块中对标签的属性进行一些更改.

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.

明显的尝试是更改 label.font.pointSize 属性,但这是只读的.

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

使用 CGAffineTransformationMakeScale()缩放标签的.transform属性会使文本模糊.

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

还有其他方法吗?

将UILabel上的字体设置为放大时所需的大小.然后按比例缩小.当您希望标签膨胀时,将其缩放回原始尺寸.

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);
    }];