YYKit之YYText阅读

NSAttributedString (YYText)

/**
 将字符串存档到数据
 @return 如果发生错误返回nil
 */
- (nullable NSData *)archiveToData;
/**
 从数据中取消归档字符串
 @param data  归档的数据
 @return 如果发生错误返回nil
 */
+ (nullable instancetype)unarchiveFromData:(NSData *)data;

检索字符的属性信息

/**
 返回第一个字符的属性
 */
@property (nullable, nonatomic, copy, readonly) NSDictionary<NSString *, id> *attributes;
/**
 返回指定索引处的字符的属性
 如果索引超出结尾,则引发`NSRangeException`接收器的字符。
 
 @param index  The index for which to return attributes. 
这个值必须位于接受器的范围内.
 
 @return 返回索引处的字符属性
 */
- (nullable NSDictionary<NSString *, id> *)attributesAtIndex:(NSUInteger)index;
/**
 返回指定索引处的字符的某属性的值
 
 如果索引超出结尾,则引发`NSRangeException`接收器的字符。
 
 @param attributeName  属性的名称
 @param index          需要返回某属性字符的索引值 
 这个值不能超过接收器的边界
 
 @return 字符的名为`attributeName`的属性的值
 index`index`,如果没有这样的属性,则为nil
 */
- (nullable id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index;

获取字符属性来作为属性

/**
 文本的字体 (只读)
 
 默认的字体是 Helvetica (Neue) 12.
 获取这个属性, 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) UIFont *font;
- (nullable UIFont *)fontAtIndex:(NSUInteger)index;
/**
 字距调整 (只读)
 
 默认是标准字距. 正数表示字距大,负数表示字距小. 如果这个属性不存在, 将使用默认字距. 
如果这个属性设置为0.0, 则不进行字距的调整.
返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSNumber *kern;
- (nullable NSNumber *)kernAtIndex:(NSUInteger)index;
/**
 前景色 (只读)
 
 默认是黑色
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) UIColor *color;
- (nullable UIColor *)colorAtIndex:(NSUInteger)index;
/**
 背景色 (只读)
 
 默认没有背景色, 为nil
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) UIColor *backgroundColor;
- (nullable UIColor *)backgroundColorAtIndex:(NSUInteger)index;
/**
 笔画宽度. (只读)
 
 默认值是 0.0 (没有笔画). 这个属性, 解释为字体点大小的百分比, 控制文本绘制模式: 正值仅用笔画效果绘图; 负值用于笔画和填充。
 概述文本的典型值为3.0。
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSNumber *strokeWidth;
- (nullable NSNumber *)strokeWidthAtIndex:(NSUInteger)index;
/**
 笔触颜色. (只读)
 
 默认值为 nil (和前景色相同).
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) UIColor *strokeColor;
- (nullable UIColor *)strokeColorAtIndex:(NSUInteger)index;
/**
 文本阴影. (只读)
 
 默认值为 nil (没有阴影).
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSShadow *shadow;
- (nullable NSShadow *)shadowAtIndex:(NSUInteger)index;
/**
 删除线的风格. (只读)
 
 默认值是 NSUnderlineStyleNone (没有删除线).
 返回第一个字符的这种属性
 */
@property (nonatomic, readonly) NSUnderlineStyle strikethroughStyle;
- (NSUnderlineStyle)strikethroughStyleAtIndex:(NSUInteger)index;
/**
 删除线的颜色. (只读)
 
 默认值是 nil (和前景色一样).
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) UIColor *strikethroughColor;
- (nullable UIColor *)strikethroughColorAtIndex:(NSUInteger)index;
/**
 下划线样式. (只读)
 
 默认值是 NSUnderlineStyleNone (没有下划线).
 返回第一个字符的这种属性
 */
@property (nonatomic, readonly) NSUnderlineStyle underlineStyle;
- (NSUnderlineStyle)underlineStyleAtIndex:(NSUInteger)index;
/**
 下划线的颜色. (只读)
 
 默认值是 nil (与前景色相同).
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) UIColor *underlineColor;
- (nullable UIColor *)underlineColorAtIndex:(NSUInteger)index;
/**
 连接形成控制. (只读)
 
 默认值为1(int). 连字属性确定在显示字符串时应使用什么类型的连字。值0表示只应使用正确呈现文本所必需的连字,1表示应使用标准连字,2表示应使用所有可用的连字。哪些连字是标准的取决于脚本和可能的字体.
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSNumber *ligature;
- (nullable NSNumber *)ligatureAtIndex:(NSUInteger)index;
/**
 文本效果. (只读)
 
 默认值是 nil (没有效果). 当前唯一被支持的值是 NSTextEffectLetterpressStyle.
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSString *textEffect;
- (nullable NSString *)textEffectAtIndex:(NSUInteger)index;
/**
 字形倾斜. (只读)
 
 默认值是 0 (不倾斜).
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSNumber *obliqueness;
- (nullable NSNumber *)obliquenessAtIndex:(NSUInteger)index;
/**
 要应用于字形的扩展因子的日志. (只读)
 
 默认值是 0 (没有扩展).
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSNumber *expansion;
- (nullable NSNumber *)expansionAtIndex:(NSUInteger)index;
/**
 字符与基线的偏移, 以点为单位. (只读)
 
 默认值是 0.
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSNumber *baselineOffset;
- (nullable NSNumber *)baselineOffsetAtIndex:(NSUInteger)index;
/**
 字形方向控制. (只读)
 
 默认值是 NO. NO表示水平字形, YES表示垂直字形
 返回第一个字符的这种属性
 */
@property (nonatomic, readonly) BOOL verticalGlyphForm;
- (BOOL)verticalGlyphFormAtIndex:(NSUInteger)index;
/**
 指定文本语言. (只读)
 
 值必须是包含区域设置标识符的NSString. 默认为
 未设置. 当此属性设置为有效标识符时,将用于选择本地化字形(如果字体支持)和特定于语言环境的换行规则.
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSString *language;
- (nullable NSString *)languageAtIndex:(NSUInteger)index;
/**
 指定双向覆盖或嵌入. (只读)
 
 请参阅 NSWritingDirection and NSWritingDirectionAttributeName.
 返回第一个字符的这种属性
 */
@property (nullable, nonatomic, strong, readonly) NSArray<NSNumber *> *writingDirection;
- (nullable NSArray<NSNumber *> *)writingDirectionAtIndex:(NSUInteger)index;
/**
 一个NSParagraphStyle对象,用于指定类似线对齐,制表符标尺,写入方向等 (只读)
 
 @discussion Default is nil ([NSParagraphStyle defaultParagraphStyle]).
 @discussion Get this property returns the first character's attribute.
 @since CoreText:6.0  UIKit:6.0  YYKit:6.0
 */
@property (nullable, nonatomic, strong, readonly) NSParagraphStyle *paragraphStyle;
- (nullable NSParagraphStyle *)paragraphStyleAtIndex:(NSUInteger)index;

获取段属性作为属性

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,288评论 19 139
  • 1. 简介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的...
    笨鸟慢飞阅读 5,874评论 0 4
  • —— Kurny 月下蓝山后,云蒸红日出。 蜻蜓点水绿,荷阴锦鳞合。 小儿池中戏,老叟空室悠。 开牖听雨...
    Kurny91阅读 359评论 3 2
  • 八十年代,随着文学的全面兴起,思想的桎梏被松动的政治一点点剥蚀,集体主义下的统一思想也逐渐由开化的个性主义消释化解...
    北游小生阅读 710评论 0 1
  • day1《低风险投资之路》1~3章,首先低风险投资要想实现高收益不要把鸡蛋放在一个篮子里,第二要选择动态平衡再投资...
    朱曼莉阅读 243评论 0 0