可以通过以下步骤实现:
application(_:didFinishLaunchingWithOptions:)
方法。if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .white
appearance.titleTextAttributes = [.foregroundColor: UIColor.black]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.black]
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().barTintColor = .white
UINavigationBar.appearance().tintColor = .black
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.black]
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.black]
}
UINavigationBarAppearance
来设置导航栏的外观,包括背景颜色和文本颜色。如果设备的iOS版本低于iOS 13,则使用旧的方式来设置导航栏的外观。backgroundColor
属性设置为.white
以将导航栏的背景颜色更改为白色。将titleTextAttributes
和largeTitleTextAttributes
属性设置为.foregroundColor: UIColor.black
以将导航栏标题的文本颜色更改为黑色。腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云