gpt4 book ai didi

ios - 如何在导航栏中使用搜索栏实现分段控制?

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

我想知道是否可以在同一个导航栏中添加一个 UISegmentedControlUISearchBar

我试图最小化我的 UISearchBar,但它不起作用:

lazy var searchBar = UISearchBar(frame: CGRect.zero)

override func viewDidLoad() {
tableView.delegate = self
tableView.dataSource = self
searchBar.searchBarStyle = .minimal
navigationItem.titleView = searchBar


}

我知道像 Apple Music 这样的应用已经做到了这一点:

enter image description here该段是否是整个 UISearchBar 的一部分也可能是一个问题。

最佳答案

试试这个

let searchBar = UISearchBar()
searchBar.placeholder = "Biblioteket ditt"
searchBar.showsScopeBar = true
searchBar.barTintColor = UIColor(white: 0.9, alpha: 0.1)
searchBar.scopeButtonTitles = ["Apple Music", "Biblioteket ditt"]

// To change UISegmentedControl color only when appeared in UISearchBar
UISegmentedControl.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .red

self.navigationItem.titleView = searchBar

以上代码截图如下:

enter image description here

关于ios - 如何在导航栏中使用搜索栏实现分段控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51351843/

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