Swift 4 中的一些变化

  • 1.字体设置方面 

之前设置字体 用这些关键字 NSFontAttributeName ,NSForegroundColorAttributeName ,NSParagraphStyleAttributeName

在swift 4 中这些都被弃用  如果使用会出现如下错误:

Use of unresolved identifier 'NSFontAttributeName'

Use of unresolved identifier 'NSForegroundColorAttributeName'

Use of unresolved identifier 'NSParagraphStyleAttributeName'

现在正确时使用方法是用   NSAttributedStringKey.font    NSAttributedStringKey.foregroundColor 等更swift化的形式代替。

比如设置导航栏title 字体样式:还可以直接使用  .font   .foregroundColor  省略  NSAttributedStringKey

  • navigationBar.titleTextAttributes = {[ NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20) ]}()

猜你喜欢

转载自www.cnblogs.com/allencelee/p/9075679.html