【问题标题】:stange behaviour UIRefreshControl with UISearchBar带有 UISearchBar 的异常行为 UIRefreshControl
【发布时间】:2014-12-16 19:02:42
【问题描述】:

当我拉动刷新时,我正在使用 UIRefreshControl 和 UISearchBar,我在 uiviewcontroller 的顶部看到一个白色背景

   UISearchBar *searchBar =
[[UISearchBar alloc] initWithFrame:
 CGRectMake(0, 0, self.tableView.frame.size.width, 44.0)];
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.tableView.tableHeaderView = searchBar;

 _refreshControl = [[UIRefreshControl alloc] init];
[_refreshControl addTarget:self action:@selector(update) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:_refreshControl];

问题是上面的白色背景

有什么想法吗?

【问题讨论】:

    标签: ios uitableview uisearchbar uirefreshcontrol


    【解决方案1】:

    为表格创建一个背景视图,并将其颜色设置为clearColor,像这样

    - (void)viewDidLoad {
        self.tableView.backgroundView = [UIView new];
        self.tableView.backgroundView.backgroundColor = [UIColor clearColor];
    }
    

    【讨论】:

    • 感谢疯狂的黑客攻击,但知道为什么会这样吗?
    • 我认为这只是 tableView 的正常行为——默认背景颜色是白色,这就是它用来绘制单元格外的顶部和底部区域的颜色。我不知道为什么只清除 tableView 上的 .backgroundColor 属性不起作用,我总是不得不指定一个视图作为背景。
    • 这对我也有用。此答案应标记为正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 2019-07-31
    • 1970-01-01
    • 2013-10-29
    • 2013-06-20
    • 1970-01-01
    相关资源
    最近更新 更多