ios - UISearchBar 'prompt' 显示不正确
<p><p>我已经像这样设置了一个 UISearchBarController:</p>
<pre><code>self.searchController = [ initWithSearchResultsController:nil];
self.searchController.searchBar.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.prompt = @"Searching Transactions Since Nov 11 2017";
self.searchController.searchBar.placeholder = @"Search";
</code></pre>
<p>这是设置<code>.prompt</code>的输出:</p>
<p> <a href="/image/rMZGe.jpg" rel="noreferrer noopener nofollow"><img src="/image/rMZGe.jpg" alt="enter image description here"/></a> </p>
<p>这就是 View 呈现和滚动时的外观。 <code>prompt</code> 应该显示在搜索栏上方,如 <a href="https://developer.apple.com/ios/human-interface-guidelines/bars/search-bars/" rel="noreferrer noopener nofollow">the HIG</a> 所示.</p>
<p>有谁知道它为什么会这样做?它是一个错误吗?还是 <code>prompt</code> 只是为了在设置单独的搜索 Controller 时正确显示?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>不确定是否是 UISearchBar 的 bug,但可以添加偏移量:</p>
<pre><code>self.searchController.searchBar.searchFieldBackgroundPositionAdjustment = UIOffsetMake(0, 20);
</code></pre>
<p>如果你有取消按钮:</p>
<pre><code>UIBarButtonItem *cancelButton = , nil];
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - UISearchBar'prompt' 显示不正确,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/47910089/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/47910089/
</a>
</p>
页:
[1]