views:

515

answers:

4

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

+1  A: 

Check out the -setTintColor: method to UISearchBar and its @property equivalent, e.g.:

searchBar.tintColor = [UIColor redColor];

or:

[searchBar setTintColor:[UIColor redColor]];

Alex Reynolds
A: 

Hmm I don't mean the tint Color but the text color that can be typed into the form in UISearchBar

Kris
+1  A: 

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

wkw
A: 

You can do the following: Just get the searchField property from the SearchBar, and then change its textColor property.

UITextField *searchField = [searchbar valueForKey:@"_searchField"];
field.textColor = [UIColor redColor]; //You can put any color here.

That's it! Now you manipulate the textField in any way possible.

GeoExperts
Hope that helped.
GeoExperts