1

iOS (5.x+ のサポート) で、UISearchBar テキストフィールドの白い背景色を別の色に変更する最も簡単な方法は何ですか? これには tintColor プロパティはありません。

4

1 に答える 1

1

この方法を次のように試すことができます。

[searchBar setSearchFieldBackgroundImage: forState:];

iOS 5より前のバージョンでは、カテゴリを次のように使用できます。

@implementation UISearchBar (BackgroundColor)

- (UITextField *)field {
    // HACK: This may not work in future iOS versions
    for (UIView *subview in self.subviews) {
        if ([subview isKindOfClass:[UITextField class]]) {
            return (UITextField *)subview;
        }
    }
    return nil;
}

- (void)setTextBackgroundColor:(UIColor *)color {
    self.field.backgroundColor = color;
}

@end
于 2012-11-16T22:47:20.477 に答える