ios - UISearchBar 'prompt' 显示不正常

标签 ios uisearchbar

我已经像这样设置了一个 UISearchBarController:

self.searchController = [[UISearchController alloc] 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";

这是设置.prompt的输出:

enter image description here

这就是 View 呈现时和滚动期间的样子。 提示 应该显示在搜索栏上方,如 the HIG 中所示.

有谁知道它为什么会这样做?这是一个错误吗?还是 提示 只是为了在设置单独的搜索 Controller 时正确显示?

最佳答案

不确定这是 UISearchBar 上的错误,但您可以添加偏移量:

self.searchController.searchBar.searchFieldBackgroundPositionAdjustment = UIOffsetMake(0, 20);

如果你有取消按钮:

UIBarButtonItem *cancelButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
[cancelButton setTitlePositionAdjustment:UIOffsetMake(0, 20) forBarMetrics:UIBarMetricsDefault];

关于ios - UISearchBar 'prompt' 显示不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47910089/

相关文章:

uinavigationcontroller - 当搜索栏显示在前一个 View 的导航栏中时,无法在插入的 vc 导航栏中更改后退按钮标题 "Search"

ios - 为什么搜索不起作用?

ios - 使用搜索栏在 Core Data 中搜索 NSSet 属性

swift - 在搜索栏(ModernSearchBar)之后重新加载表格 View

ios - 类设计和委托(delegate)

ios - 带有核心文本的自定义 UITableViewCell

ios - 使用 dispatch_async() 时 Swift 中的 Optionals 问题

IOS 当我同时按下 leftBarButtonItem 和 rightBarButtonItem 时,UINavigationViewController 有奇怪的行为

ios - 如何在 UITableView 和搜索栏中使用 "sublists"?

ios - 在将应用提交到Apple Store时,IAP verifyReceipt URL应该是沙箱还是在服务器上购买url?