我正在从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