谁能看出以下 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
and NSStrokeColorAttributeName
(它有效),但由于某种原因,它不适用于NSShadowAttributeName
. 我知道它略有不同,但我错过了什么?