iOS 7 UISearchBar UISearchBarIconSearch

Dmi*_*kiy 4 uisearchbar ios7

我遇到了iOS 7的问题.

代码

[searchBar setImage:[UIImage imageNamed:@"icon_search"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

在iOS 6和iOS 7上带来不同的图标大小.

图像尺寸为29x29和58x58 @ 2x,在iOS 6下显示正常,但在iOS 7中它的尺寸是两倍甚至更小.

可能是什么问题?谢谢!

小智 6

要自定义,UISearchBarIconSearch您需要以下代码:

[yourSearchBar setImage:[UIImage imageNamed: @"yourImage.png"]
           forSearchBarIcon:UISearchBarIconSearch
                      state:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

要正确更改图标,分辨率图像必须精确:14x14,28x28用于@ 2x,42x42用于@ 3x.

我希望这有帮助 :)


小智 5

这似乎对我有用:

UIImage* image = [UIImage imageNamed:@"icon_search"];
[[UIImageView appearanceWhenContainedIn:[UISearchBar class], nil] setBounds:CGRectMake(0, 0, image.size.width, image.size.height)];
Run Code Online (Sandbox Code Playgroud)