0

我希望整个应用程序中的 UIButtons 具有相同的外观。我尝试使用 UIAppearance 协议,但它没有为 UIButton 公开任何有趣的方法。我想更改所有 UIButtons 的 textColor 和字体。

有任何想法吗?

4

1 回答 1

2

只需继承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
于 2013-03-14T15:15:45.080 回答