您如何使用大标题使用搜索栏将导航栏的底角四舍五入
How do you round bottom corners of UINavigation bar with a search bar using large titles
尝试创建带有搜索栏和大标题的导航栏时,如何将导航栏底部的样式设置为圆角?
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
自定义导航栏有点困难。但是有一种简单的方法可以使用背景图像来实现它。您可以将图片设置为导航栏。
问题已经被 Whosebug 中的其他人问过,所以请参考那个答案。
访问:
所以我发现这行得通,但是,现在我的搜索栏文本是紫底黑字还是白底? - 我必须将视图的背景颜色设置为紫色,然后在视图顶部放置一个白色背景视图。想法?
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
}
尝试创建带有搜索栏和大标题的导航栏时,如何将导航栏底部的样式设置为圆角?
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
自定义导航栏有点困难。但是有一种简单的方法可以使用背景图像来实现它。您可以将图片设置为导航栏。
问题已经被 Whosebug 中的其他人问过,所以请参考那个答案。
访问:
所以我发现这行得通,但是,现在我的搜索栏文本是紫底黑字还是白底? - 我必须将视图的背景颜色设置为紫色,然后在视图顶部放置一个白色背景视图。想法?
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
}