OGeek|极客世界-中国程序员成长平台

标题: IOS 7无法更改搜索栏的背景图片 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:31
标题: IOS 7无法更改搜索栏的背景图片

我无法在我的 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 中无法搜索。



Best Answer-推荐答案


如果您使用文本字段并更改背景图像会更好,因为它是子类并继承相同的属性。

关于IOS 7无法更改搜索栏的背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23218217/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4