iphone - 使用 iOS 5 的外观 API 自定义 UIButton 的 titleLabel

标签 iphone objective-c ios ios5

我正在尝试使用新的外观 API 自定义 UIButton 中标题标签的外观,但没有找到任何可行的方法。看来下面的代码应该可以工作:

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

但我认为 UILabel 实际上不是按钮的 subview 。有什么想法吗?

最佳答案

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

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

未经测试,但应该可以,对吧?

编辑: 为什么不创建一个 UIButton 的子类并添加这两行?

关于iphone - 使用 iOS 5 的外观 API 自定义 UIButton 的 titleLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11766143/

相关文章:

objective-c - 向每个单元格添加额外的UIlabel

ios - (Swift Playground Template) 使用 Swift 5.1 编译的模块无法被 Swift 5.1.3 编译器导入

iphone - 如何停止 UIScrollView 调用 drawRect : on sublayers that go in/out of the visible region?

ios - 使用正则表达式验证字符串

objective-c - UIPopoverController (contentSizeForViewInPopover) 中的动态 UITableView 高度?

iphone - 使用 AQ 和音频文件流动态检测和流式传输 AAC

ios - 无法解决错误 : Unable to resolve module `./node_modules/react-native/packager/src/components` React Native

ios - 如何获取 iOS 用于显示 UITableView 标题标题的默认字体详细信息?

iphone - 如何在 iPhone 中的 Facebook 好友墙上发布消息

ios - 你能在 UIViewController 类中实现辅助功能方法吗?