如何在NavigationBar中显示UISearchBar?
我想不出该怎么做。
非常感谢您的帮助。
发布于 2012-01-30 20:22:04
要将searchBar放在navigationBar的中心位置:
self.navigationItem.titleView = self.searchBarTop;
要将searchBar放在navigationBar的左侧/右侧:
UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
self.navigationItem.rightBarButtonItem = searchBarItem;
发布于 2015-08-29 04:13:54
查看苹果的UICatalog示例代码。它展示了如何以三种不同的方式使用新的UISearchController
:模态、在导航栏中和在导航栏下面。
发布于 2019-01-16 23:43:11
Objective C代码片段
- (void)viewDidLoad {
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
if (@available(iOS 11.0, *)) {
self.navigationItem.searchController = searchController;
} else {
self.navigationItem.titleView = searchController.searchBar;
}
}
阅读更多here
https://stackoverflow.com/questions/5095477
复制相似问题