Swift 4 Label attributes

前端 未结 7 709
死守一世寂寞
死守一世寂寞 2020-12-31 09:14

I\'m moving from swift 3 to swift 4. I have UILabels that I am giving very specific text properties to the label. I\'m getting an \'unexpectedly found nil while unwrapping

7条回答
  •  再見小時候
    2020-12-31 09:42

    NSAttributedStringKey.strokeColor.rawValue is of type String

    NSAttributedStringKey.strokeColor is of type NSAttributedStringKey

    So its unable to convert String to NSAttributedStringKey . You have to use like below:

    let strokeTextAttributes: [NSAttributedStringKey : Any] = [
        NSAttributedStringKey.strokeColor : UIColor.black,
        NSAttributedStringKey.foregroundColor : UIColor.white,
        NSAttributedStringKey.strokeWidth : -2.0,
        NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 18)
    ]
    

提交回复
热议问题