Search code examples
swift2nsmutableattributedstring

Swift 2 - kCTForegroundColorAttributeName


let nameAttributes = [NSFontAttributeName:nameFont, kCTForegroundColorAttributeName:UIColor.whiteColor().CGColor] as [String:AnyObject]
var nameAttributedString = NSMutableAttributedString(string:name, attributes:nameAttributes)

I have these values which are working on Swift 1.2. But on Swift 2, they don't work.

I receive an error on first line:

'_' is not convertible to 'CFString'

And the problem is kCTForegroundColorAttributeName. Without kCTForegroundColorAttributeName, it would works. But I need it to change the color..

In addition:

kCTForegroundColorAttributeName:UIColor.whiteColor().colorWithAlphaComponent(0.7).CGColor

gives me an error:

'_' is not convertible to 'CGFloat'

In Swift 2, attributes on NSMutableAttributedString has to be [String:AnyObject] while in Swift 1.2 was [NSObject:AnyObject].

Any ideas ?


Solution

  • Why not just use NSForegroundColorAttributeName?