相关疑难解决方法(0)

37
推荐指数
2
解决办法
2万
查看次数

Swift 4 Label属性

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

nsattributedstring uilabel ios swift swift4

13
推荐指数
2
解决办法
3万
查看次数

标签 统计

ios ×2

nsattributedstring ×2

uilabel ×2

cocoa ×1

swift ×1

swift4 ×1