【发布时间】:2011-05-11 13:08:53
【问题描述】:
我收到一条警告说 setFont 已弃用?
[button setFont:[UIFont boldSystemFontOfSize:13]];
任何建议如何把它拿走请..
【问题讨论】:
标签: iphone ios objective-c
我收到一条警告说 setFont 已弃用?
[button setFont:[UIFont boldSystemFontOfSize:13]];
任何建议如何把它拿走请..
【问题讨论】:
标签: iphone ios objective-c
接受的答案有效并为一个按钮实例设置字体。如果您想为所有 UIButtons 设置应用程序宽字体,您可以这样做:
// Set font to be used for labels inside UIButtons
[[UILabel appearanceWhenContainedIn:[UIButton class], nil] setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
这在问题中没有具体提出,但如果您需要为所有标签(不在 UIButtons 内)设置字体,您可以这样做:
// Set font for all UILabels
[[UILabel appearance] setFont:[UIFont fontWithName:@"HelveticaNeue" size:13.0]];
【讨论】:
appearanceWhenContainedIn 与UIButton 一起使用,请将按钮类型设置为UIButtonTypeCustom。
UIButtons?没错,我编辑了答案以使其更清楚。
在 3.x 版本的 SDK 中不推荐直接设置按钮的字体。相反,您需要设置按钮的 titleLabel 属性。
代码:
(mybutton).titleLabel.font = [UIFont systemFontOfSize:13];
来源:http://www.iphonedevsdk.com/forum/iphone-sdk-development/26126-warning-setting-font-button.html
【讨论】:
由于 UIButton 从 iPhone OS 3.0 开始公开其 titleLabel,您必须直接为其设置字体:
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
【讨论】: