本文介绍了UISearchBar“提示"未正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个 UISearchBarController,如下所示:

I have setup a UISearchBarController like so:

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的输出:

这就是视图呈现和滚动期间的外观.prompt 应显示在搜索栏上方,如 HIG.

That is how it looks when the view presents and during scrolling. The prompt should be showing above the search bar, as seen in the HIG.

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

Does anyone know why it might be doing this? Is it a bug? Or is the prompt only meant to show properly when setting a separate search controller?

推荐答案

不确定是 UISearchBar 上的 bug,但可以添加偏移量:

Not sure it is a bug on UISearchBar, but you can add offset:

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

如果您有取消按钮:

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

这篇关于UISearchBar“提示"未正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:18