gpt4 book ai didi

ios - 如何将搜索栏添加到导航栏

转载 作者:可可西里 更新时间:2023-11-01 00:58:32 25 4
gpt4 key购买 nike

我想在导航栏的右侧添加一个由 UISearchController 管理的搜索栏。

    searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
searchController.searchBar.placeholder = "Search"
searchController.searchBar.searchBarStyle = .Minimal
searchController.searchBar.frame = CGRect(x: 0, y: 0, width: 200.0, height: 44.0)
searchController.hidesNavigationBarDuringPresentation = false
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: searchController.searchBar)

当我点击搜索栏(使其变为事件状态)时,它会覆盖整个导航栏(同时覆盖其他所有内容)而不是一小部分。我怎样才能修复它的框架?

最佳答案

将搜索栏包裹在 UIView 中似乎可以解决问题。

    searchController.searchBar.frame = CGRect(x: 0, y: 0, width: 200.0, height: 44.0)
let barContainer = UIView(frame: searchController.searchBar.frame)
barContainer.backgroundColor = UIColor.clearColor()
barContainer.addSubview(searchController.searchBar)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: barContainer)

关于ios - 如何将搜索栏添加到导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39212072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com