所以我尝试使用以下代码为我的 UISearchField 图像设置自定义图像:
UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
searchBar.placeholder = @"Search for a tag";
searchBar.delegate = self;
[searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search-bg.png"] forState:UIControlStateNormal];
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
searchField.textColor = [UIColor whiteColor];
但是我的放大镜有点问题。结果如下:
如果你仔细看,放大镜实际上是透明的,而不是白色的。在我的图像中,它被设置为白色。知道为什么会发生这种情况吗?
最佳答案
我不知道这里发生了什么,但你可以提供你自己的放大镜图像:
[self setImage:[UIImage imageNamed:@"glassImage"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
关于iphone - UISearchBar setSearchFieldBackgroundImage 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866937/