我希望整个应用程序中的 UIButtons 具有相同的外观。我尝试使用 UIAppearance 协议,但它没有为 UIButton 公开任何有趣的方法。我想更改所有 UIButtons 的 textColor 和字体。
有任何想法吗?
只需继承UIButton
并覆盖自定义初始化或便利工厂方法之一。像这样的东西:
@interface MyCustomButton: UIButton
@end
@implementation MyCustomButton
+ (UIButton *)buttonWithType:(UIButtonType)type
{
UIButton *b = [super buttonWithType:type];
b.titleLabel.textColor = [UIColor redColor];
b.titleLabel.font = [UIFont fontWithName:@"FooBar-Bold" size:3.14]; // today's Pi day
return b;
}
@end