【问题标题】:White background is showing above UISearchBar for iOS7iOS7 的 UISearchBar 上方显示白色背景
【发布时间】:2013-09-17 22:40:21
【问题描述】:

我的 viewController 有一个 UISearchBar 设置为 UITableView 的标题视图。

self.tableView.tableHeaderView = self.searchBar;

在 iOS7 中,下拉到 UISearchBar 之外会显示一个不符合使用 self.tableView.backgroundColor 设置的深色的空白。

有没有办法摆脱空白?

【问题讨论】:

    标签: ios uitableview uisearchbar ios7


    【解决方案1】:

    经过大量试验和错误,在将其设置为 tableHeaderView 之前将虚拟父 UIView 添加到 UISearchBar 可防止出现空白并正确显示 tableView 的背景颜色。

    UIView *parentView = [[UIView alloc] initWithFrame:searchRect];
    [parentView addSubview:self.searchBar];
    self.tableView.tableHeaderView = parentView;
    

    有兴趣看看是否有更好的解决方案。

    【讨论】:

      【解决方案2】:

      我建议在视图的属性检查器中启用扩展边缘选项

      【讨论】:

        【解决方案3】:

        我通过设置表格视图背景视图设法摆脱了这种颜色。

        UIView *backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
        backgroundView.backgroundColor = [UIColor clearColor];
        self.tableView.backgroundView = backgroundView;
        

        【讨论】:

        • 这对我有用:[self.tableView setBackgroundView:[UIView new]];
        • 斯威夫特 4:let backgroundView = UIView() backgroundView.backgroundColor = .clear self.tableView.backgroundView = backgroundView
        • 不需要在分配新的UIView 时将背景颜色设置为.clear
        【解决方案4】:

        因为在 时代,开发人员可能会与白色背景作斗争:

        tableView.backgroundView = UIView()

        【讨论】:

        • 为我彻底解决了这个问题。这么简单的解决方案。谢谢。
        • 使用 SWIFT 3
        猜你喜欢
        • 1970-01-01
        • 2020-08-05
        • 2013-11-27
        • 1970-01-01
        • 2013-10-18
        • 2015-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多