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