0

アプリケーション全体でUIButtonを同じように表示したい。UIAppearanceプロトコルを使用しようとしましたが、UIButtonの興味深いメソッドが公開されていません。すべてのUIButtonのtextColorとフォントを変更したいと思います。

何か案は?

4

1 に答える 1

2

UIButtonカスタム初期化メソッドまたはコンビニエンスファクトリメソッドの1つをサブクラス化してオーバーライドするだけです。このようなもの:

@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 に答える