iOS 6和7中的UISearchbar自定义

问题描述:

我想我的UISearchbar应该看起来像这样。iOS 6和7中的UISearchbar自定义

enter image description here

我已经试过这样:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Helvetica Neue" size:20]]; 

[self.seachBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"background"] forState:UIControlStateNormal]; 

[self.seachBar setImage:[UIImage imageNamed:@"SearchIcon"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal]; 

[self.seachBar setBackgroundImage:[UIImage imageNamed:@"background"]]; 
[self.seachBar setText:@"Search"]; 
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 

请指导或任何教程。

感谢

+0

你使用searchbar displaycontroller还是你的添加你的搜索栏在导航栏中 – codercat

+0

Hi iDev,我使用了searchbar displaycontroller –

请参考下面链接它更有助于你不要浪费您的宝贵时间

Right align magnifying glass icon in UISearchBar

试试这个代码

for (UIView *searchBarSubview in [searchBar subviews]) 
    { 
     if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) 
     { 

      [[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"background"]forState:UIControlStateNormal]; 
      [(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleNone]; 

      [[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"search"]]; 
      [[UISearchBar appearance] setTintColor:[UIColor clearColor]]; 
     } 

    } 

希望,你的问题就解决了......