是否可以应用笔划和填充 a NSAttributedString和a UILabel?
我正在从swift 3转到swift 4.我有UILabels,我给标签提供了非常具体的文本属性.初始化strokeTextAttributes时,我在获取"意外发现nil时解包可选值"错误.坦白说,我完全迷失了.
在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)
Run Code Online (Sandbox Code Playgroud)