UISearchBar 'prompt' Not Displaying Properly

寵の児 提交于 2019-12-24 01:15:19

问题


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";

This is the output of setting .prompt:

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.

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?


回答1:


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

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

And in case you have cancel button:

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


来源:https://stackoverflow.com/questions/47910089/uisearchbar-prompt-not-displaying-properly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!