你好,我目前正在按照教程向我的 textView 添加一些 NSformatting,但我有点卡在一行代码上我认为代码是在 swift 3 上编写的,我在 swift 4.2 上,这是一行代码swift 3 上的代码:
attributedText.addAttributes(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: length))
我发现最连贯的方法是:
attributedText.addAttributes([NSAttributedString.value(forKey: paragraphStyle)], range: NSRange(location: 0
, length: length))
但我仍然得到错误:没有更多内容,表达式类型不明确
我做错了什么?
最佳答案
首先 addAttributes:value:range
(复数)甚至在 Swift 3 中都不存在
NSParagraphStyleAttributeName
已更改为 NSAttributedString.Key.paragraphStyle
attributedText.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: length))
关于ios - NSParagraphStyle 属性名称 : Conversion from swift 3 to swift 4. 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52545655/