iphone - UISearchBar setSearchFieldBackgroundImage 问题

标签 iphone objective-c ios ipad

所以我尝试使用以下代码为我的 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];

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

enter image description here

如果你仔细看,放大镜实际上是透明的,而不是白色的。在我的图像中,它被设置为白色。知道为什么会发生这种情况吗?

最佳答案

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

[self setImage:[UIImage imageNamed:@"glassImage"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

关于iphone - UISearchBar setSearchFieldBackgroundImage 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866937/

相关文章:

ios - 获取从 NSMutableDictionary 过滤的对象组

objective-c - 为什么我无法在类里面访问该属性?

objective-c - 将现有访问 token 迁移到 Facebook iOS SDK 3.0

ios - 在横向模式下应用变换/旋转后获取 ImageView 精确帧

ios - 更改 subview Controller

ios - 图像选择器委托(delegate)错误 : cannot assign value of type

ios - NSMutableParagraphStyle 在表格单元格中为 uilabel(对齐异常)自动高度

iphone - 是否可以在touchesBegan : gets called?之后立即拉取触摸点

ios - 即使我做了深度清理并重新安装 Xcode,也无法在设备上运行 Xcode 项目,钥匙串(keychain)总是出错

iphone - 如何通过 TableView 获取索引值来删除核心数据条目