1
我正在使用CATextLayer呈現NSAttributedString。在此方法中完成後,顏色無法正確呈現。當使用CTStringAttributes完成顏色的工作,但NSAttributedString不知道它自己的大小。這是我使用的代碼:在Monotouch中使用CATextLayer顯示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();
CTStringAttributes會出現其他問題使用CTStringAttributes。下面的鏈接作爲NSAttributedString將無法知道它自己的大小。 http://stackoverflow.com/questions/17814420/cannot-access-string-size-after-setting-ctstringattributes-font – CubanAzcuy