IOS 7 UISearchBar UISearchBarIconSearch

I have a problem with iOS 7.

Code

[searchBar setImage:[UIImage imageNamed:@"icon_search"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

contains various icon sizes on iOS 6 and iOS 7.

The image size is 29x29 and 58x58 @ 2x, and it displays correctly under iOS 6, but in iOS 7 it is two or even times smaller.

What could be the problem? Thanks!

+4
source share
4 answers

To configure, UISearchBarIconSearchyou need the following code:

[yourSearchBar setImage:[UIImage imageNamed: @"yourImage.png"]
           forSearchBarIcon:UISearchBarIconSearch
                      state:UIControlStateNormal];

To correctly change the icon, the image resolution must be accurate: 14x14, 28x28 for @ 2x and 42x42 for @ 3x .

Hope this helps :)

+6
source

this works for me:

UIImage* image = [UIImage imageNamed:@"icon_search"];
[[UIImageView appearanceWhenContainedIn:[UISearchBar class], nil] setBounds:CGRectMake(0, 0, image.size.width, image.size.height)];
+5
source

UISearchBar iOS 7 UITextField - .

, UISearchBar .

UITextField *textfieldField = [searchBar valueForKey:@"_searchField"];
[searchBar setImage:[UIImage imageNamed:@"icon_search"] 
           forSearchBarIcon:UISearchBarIconSearch    
           state:UIControlStateNormal];
UIImage *whatSearchImage = [UIImage imageNamed:@"icon_search.png"];
UIImageView *whatSearchView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 29, 29)];
whatSearchView.image = whatSearchImage;
textfield.leftViewMode = UITextFieldViewModeAlways;
textfield.leftView = whatSearchView;

, UISearchBarIcon, Apple, .

, - .

+2

, , .

.

. 38x38 30x30, . , iOS , , -

0

All Articles