UISearchController UISearchBar 后台
UISearchController UISearchBar background
将UISearchController 添加到UITableView header 视图时,无法将背景设置在UISearchBar 后面。
第二张图是拖动到底部时的视图。
UITableView 在 Storyboard 中设置,没有任何 headers。
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
// Setup appearance
self.searchController.searchBar.barStyle = UIBarStyleBlack;
self.searchController.searchBar.barTintColor = BLUE;
self.searchController.searchBar.tintColor = RED;
// Setup logic
self.searchController.searchBar.scopeButtonTitles = @[ NSLocalizedString(@"students", nil), NSLocalizedString(@"professors", nil), NSLocalizedString(@"rooms", nil) ];
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
我尝试将背景添加到故事板、超级视图、UITableView,并手动添加到 UISearchBar。
更多代码可用 here。
你可以试试这个:
UIView* topview = [[UIView alloc] initWithFrame:CGRectMake(0, -480, self.view.frame.size.width, 480)];
topview.backgroundColor = BLUE;
[self.tableView addSubview:topview];
我用 UITableViewController
测试过,效果很好。
灵感来自 this answer
将UISearchController 添加到UITableView header 视图时,无法将背景设置在UISearchBar 后面。
第二张图是拖动到底部时的视图。
UITableView 在 Storyboard 中设置,没有任何 headers。
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
// Setup appearance
self.searchController.searchBar.barStyle = UIBarStyleBlack;
self.searchController.searchBar.barTintColor = BLUE;
self.searchController.searchBar.tintColor = RED;
// Setup logic
self.searchController.searchBar.scopeButtonTitles = @[ NSLocalizedString(@"students", nil), NSLocalizedString(@"professors", nil), NSLocalizedString(@"rooms", nil) ];
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
我尝试将背景添加到故事板、超级视图、UITableView,并手动添加到 UISearchBar。
更多代码可用 here。
你可以试试这个:
UIView* topview = [[UIView alloc] initWithFrame:CGRectMake(0, -480, self.view.frame.size.width, 480)];
topview.backgroundColor = BLUE;
[self.tableView addSubview:topview];
我用 UITableViewController
测试过,效果很好。
灵感来自 this answer