我无法在 IOS 7 中自定义搜索栏。
我使用以下代码来更改 IOS6 中的搜索栏背景
for (UIView * v in sarchBar.subviews)
{
if ([v isKindOfClass:NSClassFromString(@"UISearchBarTextField")])
{
v.superview.alpha = 0;
UIView *containerView = [[UIView alloc] initWithFrame:sarchBar.frame];
[containerView addSubview:v];
[self.view addSubview:containerView];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
}
}
其次,如果我自定义搜索 Controller 以删除搜索栏中的默认取消按钮,它在 IOS6 中工作正常,但使用自定义搜索 Controller ,它无法在 IOS7 中搜索。
最佳答案
如果您改用文本字段并更改背景图像会更好,因为它是子类并继承相同的属性。
关于iOS 7 无法更改搜索栏背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23218217/