largetitles = true 时设置导航栏的边框和颜色
Set border and color of navigationbar when largetitles = true
我将导航栏设置为 preferslargetitles = true。由于某种原因,颜色和底部边框消失了,变成了白色。如果它是标准的,我怎样才能保持它的颜色和边框?
这是大标题的样子:
我想要与此相同的颜色和边框:
我已经尝试设置背景颜色,但边框仍然缺失,状态栏颜色不同。
navigationController?.navigationBar.backgroundColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
我现在可以使用它了。如果有人有同样的问题,可以用这个代码来完成:
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
appearance.titleTextAttributes = [.foregroundColor: UIColor.black]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.black]
UINavigationBar.appearance().tintColor = .systemBlue
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().tintColor = .systemBlue
UINavigationBar.appearance().barTintColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
UINavigationBar.appearance().isTranslucent = false
}
你需要把这个放在
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { }
否则,第一个视图控制器没有这些更改,因为第一个视图已经加载。
感谢@Sebastion post 在这个 post 中有类似的东西:
我将导航栏设置为 preferslargetitles = true。由于某种原因,颜色和底部边框消失了,变成了白色。如果它是标准的,我怎样才能保持它的颜色和边框?
这是大标题的样子:
我想要与此相同的颜色和边框:
我已经尝试设置背景颜色,但边框仍然缺失,状态栏颜色不同。
navigationController?.navigationBar.backgroundColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
我现在可以使用它了。如果有人有同样的问题,可以用这个代码来完成:
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
appearance.titleTextAttributes = [.foregroundColor: UIColor.black]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.black]
UINavigationBar.appearance().tintColor = .systemBlue
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().tintColor = .systemBlue
UINavigationBar.appearance().barTintColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
UINavigationBar.appearance().isTranslucent = false
}
你需要把这个放在
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { }
否则,第一个视图控制器没有这些更改,因为第一个视图已经加载。
感谢@Sebastion post 在这个 post 中有类似的东西: