因此,我正在尝试使用以下代码为我的 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];
但是我的放大镜有问题。结果如下:
如果你仔细观察,放大镜实际上是透明的,而不是白色的。在图像中,我将其设置为白色。任何想法为什么会发生这种情况?