0

我正在研究搜索栏定制。我用谷歌搜索了它,但我没有找到我的问题的答案。

搜索您的比赛

我使用以下代码更改背景图像:

 searchBar.backgroundColor=[UIColor clearColor];
 [[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"search-.png"] forState:UIControlStateNormal];

 [[UISearchBar appearance] setImage:[UIImage imageNamed:@"search-magnifier"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

我已经使用代码来获取搜索栏的子视图,但它没有帮助。有没有人有什么建议?

4

2 回答 2

1

我认为您应该提供文件扩展名,例如 user2277872 的说法。

于 2013-09-25T20:51:39.210 回答
0

嗨,我使用下面的代码做了我的搜索栏问题。它工作正常。

 searchBar.layer.masksToBounds=YES;

searchBar.layer.cornerRadius=5;
searchBar.backgroundColor=[UIColor colorWithRed:71/255.f green:71/255.f blue:67/255.f alpha:1];
searchBar.backgroundImage=[UIImage imageNamed:@"search-block.png"];
UITextField *searchField;
NSUInteger numViews = [searchBar.subviews count];
for(int i = 0; i < numViews; i++)
{
    if([[searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
    { //conform?
        searchField = [searchBar.subviews objectAtIndex:i];
    }
}
if(!(searchField == nil))
{
    searchField.textColor = [UIColor whiteColor];
    [searchField setBackground: [UIImage imageNamed:@"search-block.png"]];//just add here gray image which you display in quetion
    [searchField setBorderStyle:UITextBorderStyleNone];
}
[[UISearchBar appearance] setImage:[UIImage imageNamed:@"search-magnifier"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
于 2013-09-27T06:56:51.980 回答