gpt4 book ai didi

ios - 无法使用参数列表类型(字符串 : String, 属性 : [NSObject: AnyObject]?)调用 NSAttributedString 类型的初始值设定项

转载 作者:行者123 更新时间:2023-11-29 01:34:51 24 4
gpt4 key购买 nike

我正在将代码从 XCode 6.4 迁移到 XCode 7,这个错误似乎无法解决。

func onHoldReasonAttributedTextSetup(onHoldReson : String) -> NSMutableAttributedString
{

let markerFontAttributes : [NSObject : AnyObject]? = [
NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 12.0)!,
NSForegroundColorAttributeName : UIColor(red: 0/255, green: 152/255, blue: 204/255, alpha: 1.0)
]
let onHoldText = NSAttributedString(string: "On Hold: ", attributes: markerFontAttributes)
let onHoldReasonText = NSAttributedString(string:onHoldReson)
var string = NSMutableAttributedString()
string.appendAttributedString(onHoldText)
string.appendAttributedString(onHoldReasonText)
return string
}

最佳答案

你需要改变这一行:

let markerFontAttributes : [NSObject : AnyObject]? = [
NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 12.0)!,
NSForegroundColorAttributeName : UIColor(red: 0/255, green: 152/255, blue: 204/255, alpha: 1.0)
]

let markerFontAttributes : [String : AnyObject]? = [
NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 12.0)!,
NSForegroundColorAttributeName : UIColor(red: 0/255, green: 152/255, blue: 204/255, alpha: 1.0)
]

因为初始化器需要 [String : AnyObject]? 格式的属性字典:

init(string str: String, attributes attrs: [String : AnyObject]?)

引用:NSAttributedString Class Reference

关于ios - 无法使用参数列表类型(字符串 : String, 属性 : [NSObject: AnyObject]?)调用 NSAttributedString 类型的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33081592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com