【问题标题】:How to remove the extra black line beneath UISearchBar?如何去除 UISearchBar 下方多余的黑线?
【发布时间】:2011-12-30 05:01:43
【问题描述】:

UISearchBar 的色调设置为白色后:

搜索框和表格之间多了一条黑线:

如何去除黑线?

【问题讨论】:

标签: iphone ios5 uisearchbar


【解决方案1】:

稍微调整一下……

searchBar.layer.borderWidth = 1;
searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];

【讨论】:

    【解决方案2】:

    我意识到 Legolas 的答案已经过时了 - 但我偶然发现了同样的问题,现在似乎有一个特殊的视图,而不是一个边框颜色,而是一个充当阴影的特殊视图,它产生了这种效果。

    解决此问题的唯一方法是搜索名为“_UISearchBarShadowView”的视图并将其隐藏。

    它是searchDisplayController.searchResultsTableView 的子视图的子视图,只有在搜索栏输入字符后才存在。我用下面的代码解决了这个问题。

    (getSubviewByClass 是我创建的 UIView 的一个类别,用于遍历视图并通过字符串查找子视图)

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    
        [self performSelector:@selector(searchResultsTableShouldChange) withObject:nil afterDelay:0.0001];
    
    }
    
    - (void)searchResultsTableShouldChange {
    
        [[self.view getSubviewByClass:@"_UISearchBarShadowView"] setHidden:YES];
    }
    

    【讨论】:

    • UIView 基类上没有 getSubviewByClass: 方法之类的东西。
    • 这就是为什么我在示例代码上方的括号中写了它。这是我创建的一个类别,以便更轻松地在 UIViews 中进行递归搜索。
    • 如果你想让你的应用被拒绝,这不是一个“解决方案”吗?
    【解决方案3】:

    searchBar.backgroundImage = [UIImage new];

    在此处查看“theMonster”的解释:https://stackoverflow.com/a/25275021/1751266

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-14
      相关资源
      最近更新 更多