C# 使用Monotouch中的CATextLayer显示NSAttribute字符串
我正在使用CATextLayer渲染NSAttributedString。使用此方法时,颜色无法正确渲染。使用CTStringAttributes时,颜色可以工作,但NSAttributedString不知道自己的大小。这是我正在使用的代码:C# 使用Monotouch中的CATextLayer显示NSAttribute字符串,c#,ios6,xamarin.ios,nsattributedstring,catextlayer,C#,Ios6,Xamarin.ios,Nsattributedstring,Catextlayer,我正在使用CATextLayer渲染NSAttributedString。使用此方法时,颜色无法正确渲染。使用CTStringAttributes时,颜色可以工作,但NSAttributedString不知道自己的大小。这是我正在使用的代码: var caTextLayer = new CATextLayer (); var attributedString = new NSAttributedString ( "test string",
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 ();
如果使用CoreText图层,则需要使用CTStringAttributesCTStringAttributes将出现其他问题。以下链接,因为NSAttributedString将无法知道其自身的大小。