相关疑难解决方法(0)

如何在Swift中更改CATextLayer中的文本颜色

我想更改CATextLayer的文本颜色.

这不起作用

myTextLayer.textColor
Run Code Online (Sandbox Code Playgroud)

因为没有这样的财产.通过设置前景色我也没有回应

textLayer.foregroundColor = someColor.CGColor
Run Code Online (Sandbox Code Playgroud)

当文本层设置如下

let myAttribute = [ NSFontAttributeName: UIFont(name: mongolFontName, size: fontSize )! ]
let attrString = NSMutableAttributedString(string: textLayer.displayString, attributes: myAttribute )
textLayer.frame = myFrame
textLayer.string = attrString
Run Code Online (Sandbox Code Playgroud)

我已经看到Objective-C问题CATextLayer textcolor总是黑色的,但那里的答案在我的情况下似乎没有意义.

由于我能够通过阅读文档解决我的问题,我将在下面分享答案.

textcolor ios catextlayer swift

4
推荐指数
1
解决办法
6760
查看次数

标签 统计

catextlayer ×1

ios ×1

swift ×1

textcolor ×1