我正在從swift 3移動到swift 4.我有UILabels,我將非常具體的文本屬性賦予標籤。當strokeTextAttributes被初始化時,我得到'意外發現的零,同時展開可選值'錯誤。我完全失去坦率。Swift 4標籤屬性
在swift 3中,strokeTextAttributes是[String:Any],但swift 4拋出錯誤,直到我將其更改爲下面的內容。
let strokeTextAttributes = [
NSAttributedStringKey.strokeColor.rawValue : UIColor.black,
NSAttributedStringKey.foregroundColor : UIColor.white,
NSAttributedStringKey.strokeWidth : -2.0,
NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 18)
] as! [NSAttributedStringKey : Any]
chevronRightLabel.attributedText = NSMutableAttributedString(string: "0", attributes: strokeTextAttributes)
'NSAttributedStringKey.strokeColor.rawValue' =>'NSAttributedStringKey.strokeColor'呢? – Larme
與一般編程相比,Swift是一個絕對的噩夢,也是重要的一步。 – RunLoop