我需要通过编程方式设置UIButton标题UILabel的字体大小。


当前回答

斯威夫特3:

myButton.titleLabel?.font = myButton.titleLabel?.font.withSize(40)

其他回答

您还可以自定义按钮字体粗体,斜体。 本例采用系统粗体字体大小。

[LoginButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0f*Ratio]];

斯威夫特3:

myButton.titleLabel?.font = myButton.titleLabel?.font.withSize(40)

【按钮setFont:……已被弃用。

使用[按钮。titleLabel setFont:…而是,例如:

[myButton.titleLabel setFont:[UIFont systemFontOfSize:10]];

迅速:

shareButton.titleLabel?.font = UIFont.systemFontOfSize(size)

重要注意事项: 删除由animuson♦12月5日14日16:48 animuson,在我发布这个答案一个月后,我现在也有同样的问题。我在谷歌上搜索,发现这篇文章不容易复制粘贴到一个快速的项目中。当我滚动看到我删除的答案,并复制它。所以请不要删除真正有用的东西。

objective - c:

[button.titleLabel setFont: [button.titleLabel.font fontWithSize: sizeYouWant]];

迅速:

button.titleLabel?.font = button.titleLabel?.font.fontWithSize(sizeYouWant)

只会改变字体大小。