导航栏标题背景在 iOS11 中为白色
Navigation Bar Title background is white in iOS11
出于某种原因,在 iOS11 中,导航栏中的标题标签具有白色背景:
这只是一个普通的导航控制器,标题设置为默认方式:
self.title = @"My Title";
此问题仅在 iOS 11 中发生,并且屏幕截图是从模拟器中截取的,否则对于以前的 iOS 版本,它可以正常工作。
关于我如何拥有正常的清晰背景标签或删除出于某种原因出现的白色背景,有什么建议吗?
检查标题文本属性是否设置正确。您可以从故事板或以编程方式设置标题文本属性。 SelectStoryboard -> NavigationBar -> Go to attribute inspector -> Title Text Attributes
或在 ViewController 中尝试手动设置
Swift 4:
self.navigationController?.navigationBar.titleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor.white,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17, weight: .bold)
]
Swift 3:
self.navigationController?.navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
NSFontAttributeName: UIFont.systemFont(ofSize: 17, weight: .bold)
]
出于某种原因,在 iOS11 中,导航栏中的标题标签具有白色背景:
这只是一个普通的导航控制器,标题设置为默认方式:
self.title = @"My Title";
此问题仅在 iOS 11 中发生,并且屏幕截图是从模拟器中截取的,否则对于以前的 iOS 版本,它可以正常工作。
关于我如何拥有正常的清晰背景标签或删除出于某种原因出现的白色背景,有什么建议吗?
检查标题文本属性是否设置正确。您可以从故事板或以编程方式设置标题文本属性。 SelectStoryboard -> NavigationBar -> Go to attribute inspector -> Title Text Attributes
或在 ViewController 中尝试手动设置
Swift 4:
self.navigationController?.navigationBar.titleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor.white,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17, weight: .bold)
]
Swift 3:
self.navigationController?.navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
NSFontAttributeName: UIFont.systemFont(ofSize: 17, weight: .bold)
]