Michel
Michel

Reputation: 11763

NSShadowAttributeName not working

Can anyone see what is wrong in the following Swift code?

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)
}

I use similar code to change the NSForegroundColorAttributeName and NSStrokeColorAttributeName (it works) but for some reason here it does not work with NSShadowAttributeName. I know it is slightly different, but what am I missing?

Upvotes: 2

Views: 1003

Answers (0)

Related Questions