ios - UISearchController UISearchBar 背景
<p><p>当给 UITableView 头部 View 添加 UISearchController 时,不可能在 UISearchBar 后面设置背景。</p>
<p>第二张图是拖到底部时的 View 。</p>
<p> <img src="/image/x9dYW.png" alt="Normal"/>
<img src="/image/OIFKP.png" alt="Dragging"/> </p>
<p>UITableView 在 Storyboard 中设置,没有任何标题。</p>
<pre><code>self.searchController = [ 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;
</code></pre>
<p>我尝试将背景添加到 Storyboard 、 superView 、UITableView 以及手动添加到 UISearchBar。</p>
<p>更多代码可用<a href="https://github.com/thegameg/EpiTime-iOS/blob/master/EpiTime/Groups/ETGroupsViewController.m" rel="noreferrer noopener nofollow">here</a> .</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以试试这个:</p>
<pre><code>UIView* topview = [ initWithFrame:CGRectMake(0, -480, self.view.frame.size.width, 480)];
topview.backgroundColor = BLUE;
;
</code></pre>
<p>我已经用 <code>UITableViewController</code> 进行了测试,它工作正常。</p>
<p>灵感来自 <a href="https://stackoverflow.com/a/1485023/2433921" rel="noreferrer noopener nofollow">this answer</a> </p></p>
<p style="font-size: 20px;">关于ios - UISearchController UISearchBar 背景,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/28714620/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/28714620/
</a>
</p>
页:
[1]