我正在使用CATextLayer来渲染NSAttributedString。在此方法中完成时,颜色无法正确呈现。使用CTStringAttributes完成时颜色有效,但NSAttributedString不知道自己的大小。这是我正在使用的代码:
var caTextLayer = new CATextLayer ();
var attributedString = new NSAttributedString
(
"test string",
ForegroundColor = UIColor.Blue.CGColor,
Font = new CTFont ("Arial", 24),
KerningAdjustment = 72f
);
caTextLayer.AttributedString = attributedString;
caTextLayer.Frame = UIScreen.MainScreen.Bounds;
caTextLayer.ContentsScale = UIScreen.MainScreen.Scale;
myViewController.View.Layer.InsertSublayer(layer3, 1);
caTextLayer.SetNeedsDisplay ();
答案 0 :(得分:0)
如果您使用的是CoreText图层,则需要使用CTStringAttributes