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

这就是视图显示时和滚动过程中的外观。如the HIG中所示,prompt应显示在搜索栏的上方。
有人知道为什么它会这样做吗?这是个bug吗?或者,prompt只有在设置单独的搜索控制器时才能正确显示?
发布于 2018-11-14 00:00:58
不确定这是UISearchBar上的错误,但可以添加偏移量:
self.searchController.searchBar.searchFieldBackgroundPositionAdjustment = UIOffsetMake(0, 20);如果你有取消按钮:
UIBarButtonItem *cancelButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
[cancelButton setTitlePositionAdjustment:UIOffsetMake(0, 20) forBarMetrics:UIBarMetricsDefault];https://stackoverflow.com/questions/47910089
复制相似问题