Alex Rivera | Logout

UISearchBar text color

Asked 2009-09-10T21:29:06.740
12

Browsed the documentation and I couldn't find anything to change the color of UISearchBar. Does anybody know how to change it? There isn't any textColor property :/

Thx

Edit
Report

1 Answer

3

I suspect you could use techniques described in this post

Modifying the code presented there slightly, you subclass UISearchBar:

@interface SearchBar : UISearchBar {
}
@end

Then in your implementation:

- (void)layoutSubviews {
    UITextField *searchField;
    NSUInteger numViews = [self.subviews count];
    for(int i = 0; i < numViews; i++) {
        if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
            searchField = [self.subviews objectAtIndex:i];
        }
    }
    if(!(searchField == nil)) {
        searchField.textColor = [UIColor redColor];
    }

    [super layoutSubviews];
}

I haven't tested either the original post's code or this code, but looks like it ought to work. -wkw

answered 2009-11-07T16:09:41.963

Your Answer