OGeek|极客世界-中国程序员成长平台

标题: ios - UISearchController UISearchBar 背景 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:21
标题: ios - UISearchController UISearchBar 背景

当给 UITableView 头部 View 添加 UISearchController 时,不可能在 UISearchBar 后面设置背景。

第二张图是拖到底部时的 View 。

Normal Dragging

UITableView 在 Storyboard 中设置,没有任何标题。

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;

我尝试将背景添加到 Storyboard 、 super View 、UITableView 以及手动添加到 UISearchBar。

更多代码可用here .



Best Answer-推荐答案


你可以试试这个:

UIView* topview = [[UIView alloc] initWithFrame:CGRectMake(0, -480, self.view.frame.size.width, 480)];
topview.backgroundColor = BLUE;

[self.tableView addSubview:topview];

我已经用 UITableViewController 进行了测试,它工作正常。

灵感来自 this answer

关于ios - UISearchController UISearchBar 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28714620/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4