How to customize appearance of UISearchBar
// Search Bar Customization
// Background Image
[self.searchDisplayController.searchBar setBackgroundImage:[[UIImage alloc]init]];
// Backgroud Color
[self.searchDisplayController.searchBar setBackgroundColor:[UIColor redColor]];
// Search Bar Cancel Button Color
[[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]];
// set Search Bar Search icon
[self.searchDisplayController.searchBar setImage:[UIImage imageNamed:@"search_ico.png"]
forSearchBarIcon:UISearchBarIconSearch
state:UIControlStateNormal];
// set Search Bar textfield background image
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_box.png"]
forState:UIControlStateNormal];
// set Search Bar texfield corder radius
UITextField *txfSearchField = [self.searchDisplayController.searchBar valueForKey:@"_searchField"];
txfSearchField.layer.cornerRadius = 10.8f;
By IOS 5.0 you have the chance to use
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"searchbar.png"]forState:UIControlStateNormal];
Here is some common properties you can change to customize UISearchBar:
Here is the solution I was looking for: Subclassing a UISearchBar, & overwriting the method layoutSubviews
- (void)layoutSubviews {
UITextField *searchField;
NSUInteger numViews = [self.subviews count];
for(int i = 0; i < numViews; i++) {
if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
searchField = [self.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.textColor = [UIColor whiteColor];
[searchField setBackground: [UIImage imageNamed:@"buscador.png"] ];
[searchField setBorderStyle:UITextBorderStyleNone];
}
[super layoutSubviews];
}