1.Use this code to change the search bar
UITextField
will backgroundimage
UITextField *searchField;NSUInteger numViews = [searchBar.subviews count];for(int i = 0; i < numViews; i++) { if([[searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform? searchField = [searchBar.subviews objectAtIndex:i]; }}if(!(searchField == nil)) { searchField.textColor = [UIColor whiteColor]; [searchField setBackground: [UIImage imageNamed:@"yourImage"]];//just add here gray image which you display in quetion [searchField setBorderStyle:UITextBorderStyleNone];}
theCorrugated PipeChanges in code
UISearchBarIcon
UIImageView *searchIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourSearchBarIconImage"]];searchIcon.frame = CGRectMake(10, 10, 24, 24);[searchBar addSubview:searchIcon];[searchIcon release];
also for changing the Searcbar icon Search bar which of your available iOS 5 +
- (void)setImage:(UIImage *)iconImage forSearchBarIcon:(UISearchBarIcon)icon state:(UIControlState)state
Here you can set up 4 kinds of
UISearchBarIcon
that
UISearchBarIconBookmark
UISearchBarIconClear
UISearchBarIconResultsList
UISearchBarIconSearch
I hope this can help you ...
2.According to the Uisearchbar you this function applies to iOS 5.0 +.
- (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state
Use cases:
[mySearchBar setSearchFieldBackgroundImage:myImage forState:UIControlStateNormal];
Sadly, in iOS 4 you need to revert to the other answers that are less visible.
3.just the custom text field itself. I'm just doing this and it works fine (iOS 7).
UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];txfSearchField.backgroundColor = [UIColor redColor];
this way, you don't need to create an image, its size, and so on .
4.for changing colors only:
searchBar.tintColor = [UIColor redColor];
to apply a background image:
[self.searchBar setSearchFieldBackgroundImage: [UIImage imageNamed:@"Searchbox.png"] forState:UIControlStateNormal];
5.for private APIs:
for (UIView* subview in [[self.searchBar.subviews lastObject] subviews]) { if ([subview isKindOfClass:[UITextField class]]) { UITextField *textField = (UITextField*)subview; redColor]]; }}
Uisearchbar change edit to Background color