NavigationItem.searchController的searchBar使用整个屏幕的宽度可以通过以下步骤实现:
class SearchController: UISearchController {
override init(searchResultsController: UIViewController?) {
super.init(searchResultsController: searchResultsController)
self.searchBar.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
let searchController = SearchController(searchResultsController: nil)
navigationItem.searchController = searchController
override func viewDidLoad() {
super.viewDidLoad()
definesPresentationContext = true
}
这样,NavigationItem.searchController的searchBar就会使用整个屏幕的宽度。
推荐的腾讯云相关产品:腾讯云移动推送服务(https://cloud.tencent.com/product/umeng_push)
领取专属 10元无门槛券
手把手带您无忧上云