如何为UINavigationBar标题设置自定义字体名称和自定义字体粗细(字体样式)?
答案 0 :(得分:1)
将UIFontDescriptor
用作Font Name
和Font Size
UIFontDescriptor.fontDescriptorWithSymbolicTraits
字体样式(Bold,Italic,...)
Swift 2.x:
let fontDec = UIFontDescriptor(name: "FontName", size: 20)
fontDec.fontDescriptorWithSymbolicTraits(.TraitBold)
let font = UIFont(descriptor: fontDec, size: 20)
self.navigationBar.titleTextAttributes = [
NSFontAttributeName: font,
NSForegroundColorAttributeName: UIColor.redColor()]
可能是性能问题。
答案 1 :(得分:1)
Try this code. Swift 3x
This could be a better approach to set nanvigationBar title font and Style.
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.ANY COLOUR, NSFontAttributeName:UIFont(name:"FontName-FontStyle", size: ANY SIZE)!]
Some Font Styles:
Regular,Bold,BoldItalic,CondensedBlack,CondensedBold,Italic,Light,LightItalic,Thin,ThinItalic,UltraLight,UltraLightItalic
Note: Font style varies from font to font!
答案 2 :(得分:-1)
快速4倍:
let newFont = UIFont(名称:“ FontName”,大小:15) newFont?.fontDescriptor.withSymbolicTraits(.traitBold)