自定义的UIButton的titleLabel与iOS 5的外观API

问题描述:

我想自定义标题标签的一个UIButton在外观上采用了全新的外观API,但没有发现任何东西,将工作。看来,下面的代码应该工作:自定义的UIButton的titleLabel与iOS 5的外观API

[[UILabel appearanceWhenContainedIn:[UIButton class], nil] setShadowOffset:CGSizeMake(0, 2)]; 
[[UILabel appearanceWhenContainedIn:[UIButton class], nil] setFont:[UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:17]]; 

但我想UILabel实际上不是按钮的子视图。有任何想法吗?

+1

我遇到同样的问题。我认为按钮可能会覆盖这里的外观。 – wbyoung 2013-05-24 20:34:37

你为什么不直接使用的UIButtontitleLabel属性修改标题标签?

button.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:17]; 
button.titleLabel.shadowOffset = CGSizeMake(0, 2); 

未经测试,但应该工作,对不对?

编辑: 你为什么不只是创建的UIButton的子类,并添加以下两行?

+4

这将工作的单个UIButton,但我想要做的是风格的所有UIButtons。 – Austin 2012-08-01 19:34:46

+0

我想我可以创建一个子类,但我希望尽可能在框架中尽可能多地做。 – Austin 2012-08-01 19:41:28

+0

什么框架?您仍在使用UIKit ... – James 2012-08-01 19:42:57