可以在iPhone上通过流畅的动画更改UILabel的字体大小吗? [英] Can font size of UILabel be changed with smooth animation on iPhone?

查看:57
本文介绍了可以在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);
    }];

这篇关于可以在iPhone上通过流畅的动画更改UILabel的字体大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆