我进行了大量搜索并阅读了很多问题/答案,但我仍然无法在导航栏下方编写静态搜索栏......(换句话说,搜索栏固定在导航栏上)
我想要这样的东西:
但是我不知道怎么做。
这是我写的代码:
let searchBar = UISearchBar()
searchBar.placeholder = "Search"
searchBar.frame = CGRect(x: 0, y: 0, width: (navigationController?.view.bounds.size.width)!, height: 64)
searchBar.barStyle = .default
searchBar.isTranslucent = false
searchBar.barTintColor = UIColor.red
searchBar.backgroundImage = UIImage()
view.addSubview(searchBar)
当我向上滚动时,搜索栏不会粘在导航栏上。我想为这两个部分准备一个积木。
最佳答案
按照下面的步骤在UINavigationBar
下实现一个静态的UISearchBar
将
UISearchBar
从 Interface Builder 拖到 Storyboard 中的 ViewController。为
UISearchBar
设置约束- 置顶
- 领导
- 尾随
- 固定高度
关于ios - 导航栏下方添加 "static"搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44024288/