Reputation: 111
I am working on searchbar customization. I googled it, and I did not find an answer to my problem.
I used the following code to change background image:
searchBar.backgroundColor=[UIColor clearColor];
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"search-.png"] forState:UIControlStateNormal];
[[UISearchBar appearance] setImage:[UIImage imageNamed:@"search-magnifier"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
I already used the code for getting subviews of searchbar, but it did not help. Does anyone have any suggestions?
Upvotes: 0
Views: 119
Reputation: 111
Hi i did my searchbar issue using below code. its working fine.
searchBar.layer.masksToBounds=YES;
searchBar.layer.cornerRadius=5;
searchBar.backgroundColor=[UIColor colorWithRed:71/255.f green:71/255.f blue:67/255.f alpha:1];
searchBar.backgroundImage=[UIImage imageNamed:@"search-block.png"];
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:@"search-block.png"]];//just add here gray image which you display in quetion
[searchField setBorderStyle:UITextBorderStyleNone];
}
[[UISearchBar appearance] setImage:[UIImage imageNamed:@"search-magnifier"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
Upvotes: 0
Reputation: 85
I think you should give file extension like sayings of user2277872 .
Upvotes: 1