我已经像这样设置了一个 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
的输出:
这就是 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/