我正在尝试使用带字距调整和特定字体的字符串呈现CATextLayer。如果我使用CATextLayer设置字体,则字体无法正确呈现。如果我在CTStringAttributes中设置字体,那么我得到以下错误:
Unhandled Exception:
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.
Name: NSInvalidArgumentException
Reason: -[__NSCFType screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x13dba570
以下是我尝试使用的代码:
CTStringAttributes ctsa = new CTStringAttributes();
//This method returns what out kerning should be loosely based on the
//tracking number our UI designer uses in Adobe Illustrator
var trackingSize = MyFonts.IllustratorTracking(200f * 0.8f,
MyFonts.CardHeader.PointSize);
ctsa.KerningAdjustment = trackingSize;
ctsa.ForegroundColor = MyColors.CardHeaderText.CGColor;
ctsa.Font = MyFonts.CardHeaderCT;
NSAttributedString someString = new NSAttributedString(title, ctsa);
titleLayer = new CATextLayer();
titleLayer.Frame = new RectangleF(19, ((20 - someString.Size.Height) / 2.0f),
someString.Size.Width,
someString.Size.Height);
titleLayer.ForegroundColor = MyColors.CardHeaderText.CGColor;
titleLayer.BackgroundColor = UIColor.Clear.CGColor;
titleLayer.AttributedString = someString;
headerView.Layer.AddSublayer(titleLayer);