How to change the text color in a CATextLayer in Swift
<p>I want to change the text color of a CATextLayer. </p>

<p>This does not work</p>

<pre><code>myTextLayer.textColor
</code></pre>

<p>since there is no such property. I also got no response by setting the foreground color</p>

<pre><code>textLayer.foregroundColor = someColor.CGColor
</code></pre>

<p>when the text layer is set up as follows</p>

<pre><code>let myAttribute = [ NSFontAttributeName: UIFont(name: mongolFontName, size: fontSize )! ]
let attrString = NSMutableAttributedString(string: textLayer.displayString, attributes: myAttribute )
textLayer.frame = myFrame
textLayer.string = attrString
</code></pre>

<p>I have seen the Objective-C question <a href="https://stackoverflow.com/questions/16331345/catextlayer-textcolor-is-always-black">CATextLayer textcolor is always black</a> but the answers there didn't seem to make sense in my situation. </p>

<p>Since I was able to solve my problem by reading the <a href="https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CATextLayer_class/#//apple_ref/occ/instp/CATextLayer/foregroundColor" rel="nofollow noreferrer">documentation</a>, I am sharing the answer below.</p>