Nit*_*ish 2 nsattributedstring ios swift swift3
这就是我想要实现的目标:
var range : NSRange? = NSMakeRange(0, (attributedString?.length)!)
attributedString?.attribute(NSFontAttributeName: UIFont.fontNames(forFamilyName: "OpenSans-Regular"), at: 1, effectiveRange: &range)
Run Code Online (Sandbox Code Playgroud)
在第二行,我收到一个编译时错误:
参数标签 '(NSFontAttributeName:, at:, EffectiveRange:)' 不匹配任何可用的重载
你需要:
var range = NSRange(location: 0, length: attributedString?.length)
let font = attributedString?.attribute(NSFontAttributeName, at: 1, effectiveRange: &range)
Run Code Online (Sandbox Code Playgroud)
第一个参数只是您要检查的属性。您没有传入特定的字体。此方法将告诉您要在指定位置找到字体。