1、CATextLayer简介
CATextLayer快速高效简单地来渲染纯文本、NSAttributedString
/* The text layer provides simple text layout and rendering of plain * or attributed strings. The first line is aligned to the top of the * layer. */ NS_ASSUME_NONNULL_BEGIN CA_CLASS_AVAILABLE (10.5, 2.0, 9.0, 2.0) @interface CATextLayer : CALayer { @private struct CATextLayerPrivate *_state; } //渲染的字符串 @property(nullable, copy) id string; //字体 @property(nullable) CFTypeRef font; //字号 @property CGFloat fontSize; //文字颜色 @property(nullable) CGColorRef foregroundColor; //是否换行,默认NO @property(getter=isWrapped) BOOL wrapped; //枚举:设置截断模式 @property(copy) NSString *truncationMode; //枚举:设置对其模式 @property(copy) NSString *alignmentMode; //文字是否像素化,默认NO @property BOOL allowsFontSubpixelQuantization; @end /* Truncation modes. */ CA_EXTERN NSString * const kCATruncationNone //不剪裁,默认 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCATruncationStart //剪裁开始部分 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCATruncationEnd //剪裁结束部分 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCATruncationMiddle //剪裁中间部分 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); /* Alignment modes. */ CA_EXTERN NSString * const kCAAlignmentNatural //默认 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCAAlignmentLeft //左对齐 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCAAlignmentRight //右对齐 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCAAlignmentCenter //居中对齐 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); CA_EXTERN NSString * const kCAAlignmentJustified //两端对齐 CA_AVAILABLE_STARTING (10.5, 3.2, 9.0, 2.0); NS_ASSUME_NONNULL_END
时间: 2024-10-24 14:41:46