我将我的searchBar(左)和一个按钮(右)作为子视图添加到UIView.Then将UIView设置为TableHeaderView.But我结束搜索后点击取消按钮返回到tableview,searchBar将完全覆盖tableHeaderView并且无法看到添加的按钮。我查看了图层,按钮仍然存在,只是被扩展的搜索栏所覆盖。有人知道如何解决这个问题吗?提前感谢!
self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WinWidth, 40)];
self.searchController.searchBar.frame = CGRectMake(0, 0, WinWidth-50, 40);
UIButton *filterBtn = [[UIButton alloc]initWithFrame:CGRectMake(WinWidth-30, 10, 20, 20)];
filterBtn setBackgroundImage:[UIImage imageNamed:@"arrow_expend_down"] forState:UIControlStateNormal];
[view addSubview:self.searchController.searchBar]; [self.searchController.searchBar addSubview:filterBtn];
self.searchController.searchBar.barTintColor = [self colorWithRGB:0xf2f2f2 alpha:1];
[view addSubview:filterBtn];
view.backgroundColor =self.searchController.searchBar.barTintColor; self.tableView.tableHeaderView = view;
答案 0 :(得分:0)
尝试添加:tableView.tableHeaderView.contentMode = UIViewContentModeCenter;
答案 1 :(得分:0)
试试这个
[self.searchController.searchBar sizeToFit];