NSShadowAttributeName不起作用

时间:2015-11-19 08:34:02

标签: ios swift nsattributedstring nsshadow

任何人都可以看到以下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)
}

我使用类似的代码来更改NSForegroundColorAttributeNameNSStrokeColorAttributeName(它有效)但由于某种原因,它不适用于NSShadowAttributeName。我知道这有点不同,但我错过了什么?

0 个答案:

没有答案