iOS 6和iOS 7中的UISearchbar自定义

iOS 6和iOS 7中的UISearchbar自定义,ios,iphone,custom-controls,uisearchbar,Ios,Iphone,Custom Controls,Uisearchbar,我希望我的UISearchbar看起来像这样 我试过这个: [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Helvetica Neue" size:20]]; [self.seachBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"background"] forState:UICon

我希望我的UISearchbar看起来像这样

我试过这个:

[[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]];
请参考指南或任何教程

谢谢

试试这段代码

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

    }

希望,你的问题解决了…

请参考下面的链接,它会对你更有帮助,你不会浪费宝贵的时间


您是使用searchbar displaycontroller还是在NavigationBar中添加搜索栏Hi iDev,我使用searchbar displaycontroller