任何人都可以看到以下Swift代码中的错误吗?
func myFunction(color:UIColor) {// Changes the Shadow color on textLabel
var attributes = textLabel.attributedText?.attributesAtIndex(0, effectiveRange: nil)
let shadow = attributes![NSShadowAttributeName] as! NSShadow
shadow.shadowColor = color
let mutabAttrString = NSMutableAttributedString(attributedString: textLabel.attributedText!)
mutabAttrString.removeAttribute(NSShadowAttributeName, range: NSMakeRange(0,mutabAttrString.length))
mutabAttrString.addAttribute(NSShadowAttributeName, value: shadow, range: NSMakeRange(0,mutabAttrString.length))
textLabel.attributedText = NSAttributedString(attributedString: mutabAttrString)
}
我使用类似的代码来更改NSForegroundColorAttributeName
和NSStrokeColorAttributeName
(它有效)但由于某种原因,它不适用于NSShadowAttributeName
。我知道这有点不同,但我错过了什么?