2014-01-31 72 views
1

我想我的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 –

回答

2

試試這個代碼

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]]; 
     } 

    } 

希望,你的問題就解決了......