[英]How do you round bottom corners of UINavigation bar with a search bar using large titles
When attempting to crate a UINavigationBar with a search bar and large title, how do you style the bottom of the navigation bar to have rounded corners?尝试使用搜索栏和大标题创建 UINavigationBar 时,如何将导航栏底部设置为圆角?
self.navigationController?.navigationBar.prefersLargeTitles = true
search.searchBar.delegate = self
search.searchBar.sizeToFit()
search.obscuresBackgroundDuringPresentation = false
search.hidesNavigationBarDuringPresentation = true
self.definesPresentationContext = true
search.searchBar.placeholder = "Search here"
self.navigationItem.searchController = search
Customizing Navigation Bar is some what difficult.自定义导航栏有些困难。 But there is an easy way to achieve it using background image.
但是有一种简单的方法可以使用背景图像来实现它。 You can set Image to the navigation bar.
您可以将图像设置为导航栏。
Question is already asked by someone else in the stackoverflow so, refer that answer. stackoverflow 中的其他人已经提出了问题,因此请参考该答案。
Visit: https://stackoverflow.com/a/61620703/12775090访问: https ://stackoverflow.com/a/61620703/12775090
so I found that this works, however, now my search bar text is black on purple vs white?所以我发现这行得通,但是,现在我的搜索栏文本在紫色和白色上是黑色的? - And I had to set the background color of the view to my purple color and then place a white background view on top of the view.
- 我必须将视图的背景颜色设置为紫色,然后在视图顶部放置一个白色背景视图。 Thoughts?
想法?
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.layer.cornerRadius = 30
self.navigationController?.navigationBar.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
self.navigationController?.navigationBar.clipsToBounds = true
let app = UINavigationBarAppearance()
app.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
app.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
app.backgroundColor = UIColor(red: 0.30, green: 0.07, blue: 0.63, alpha: 1.00)
self.navigationController?.navigationBar.scrollEdgeAppearance = app
self.navigationController?.navigationBar.isOpaque = true
search.searchBar.delegate = self
UISearchBar.appearance().tintColor = .white
search.searchBar.searchTextField.textColor = .white
search.searchBar.sizeToFit()
search.obscuresBackgroundDuringPresentation = false
search.hidesNavigationBarDuringPresentation = false
self.definesPresentationContext = true
search.searchBar.placeholder = "Search here"
self.navigationItem.searchController = search
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.