我正在使用 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 ();