1

因此,我正在尝试使用以下代码为我的 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];

但是我的放大镜有问题。结果如下:

在此处输入图像描述

如果你仔细观察,放大镜实际上是透明的,而不是白色的。在图像中,我将其设置为白色。任何想法为什么会发生这种情况?

4

1 回答 1

1

我不知道这里发生了什么,但您可以提供自己的放大镜图像:

[self setImage:[UIImage imageNamed:@"glassImage"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
于 2013-01-25T16:08:51.560 回答