setFont已弃用?
由于UIButton的暴露了其titleLabel从iPhone开始OS 3.0,你必须直接设置字体给它:
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
设置该按钮的字体直接在SDK的3.x版本中进行了描述。相反,您需要设置按钮的titleLabel属性的属性。
代码:
(mybutton).titleLabel.font = [UIFont systemFontOfSize:13];
来源:http://www.iphonedevsdk.com/forum/iphone-sdk-development/26126-warning-setting-font-button.html
接受的答案的作品,并设置一个按钮实例的字体。如果你想设置应用广泛的字体为所有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]];
这是一个好主意。可悲的是,UILabel没有UIAppearance代理中的字体属性,这就是为什么字体不起作用。看到这个答案http://*.com/questions/17127921/appearance-proxy-not-working-as-intended-for-uibutton-font – 2014-05-07 07:44:34
@EvaMadrazo你能详细说明什么是行不通的?我在我的项目中使用上面的代码,它工作正常。为了让'appearanceWhenContainedIn'处理'UIButton',将按钮类型设置为'UIButtonTypeCustom'。 – lekksi 2014-05-07 11:44:25
@EvaMadrazo哦,你的意思是“为所有标签设置字体”不适用于'UIButton's?这是真的,我编辑答案更加清晰。 – lekksi 2014-05-07 11:50:53
感谢您的信息! :) – 2013-04-03 13:21:38