正确设置CATextLayer的Font

来源:互联网 发布:食品科学与数据分析 编辑:程序博客网 时间:2024/05/16 04:46

iOS中,通常设置字体都是使用UIFont, 但是CATextLayer例外,详细阅读CATextLayer Class Reference,

May be either a CTFontRef, aCGFontRef, an instance ofNSFont (Mac OS X only), or a string naming the font. In iOS, you cannot assign aUIFont object to this property. Defaults to Helvetica.

The font property is only used when the string property is not an NSAttributedString.

Note: If the font property is a CTFontRef, a CGFontRef, or an instance of NSFont, the font size of the property is ignored.

设置CATextLayer字体:

错误: textLayer.font = [UIFont fontWithName:@"HiraKakuProN-W3" size:12];
正确: textLayer.font = @"HiraKakuProN-W3"; textLayer.fontSize = 12;
原创粉丝点击