微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – 通过NSAttributedString进行攻击:“没有更多上下文的表达式是模糊的”

谁能告诉我什么是错的?

let myTitle = NSAttributedString(string: Xdevices[row].deviceName!,attributes: [NSFontAttributeName:UIFont(name: "Georgia",size: 
              15.0)!,NSForegroundColorAttributeName:UIColor.orangeColor(),NsstrikethroughStyleAttributeName: NSUnderlinestyle.StyleSingle])

错误是:

Type of expression is ambiguous without more context

插入NsstrikethroughStyleAttributeName:NSUnderlinestyle.StyleSingle后发生这种情况

解决方法

试试这个:

let attributes = [
    NSFontAttributeName: UIFont(name: "Georgia",size: 15.0)!,NSForegroundColorAttributeName: UIColor.orangeColor(),NsstrikethroughStyleAttributeName: NSNumber(integer: NSUnderlinestyle.StyleSingle.rawValue)
]

let myTitle = NSAttributedString(string: Xdevices[row].deviceName!,attributes: attributes)

NSAttributedString(string:attributes :)需要一个类型为[String:AnyObject]的字典.然而,StyleSingle是一个Int.因此,您必须将其包装在NSNumber中.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐