Swift 2 - kCTForegroundColorAttributeName

1k views Asked by At
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 ?

2

There are 2 answers

0
Ken Thomases On BEST ANSWER

Why not just use NSForegroundColorAttributeName?

0
Maninderjit Singh On

Use this Code

let attrs2 = [NSFontAttributeName : FontWithBook(10),NSForegroundColorAttributeName :UIColor.grayColor()]
var gString = NSMutableAttributedString(string:"(Mandatory)", attributes:attrs2)