版本记录
版本号 | 时间 |
---|---|
V1.0 | 2018.03.31 |
前言
iOS圈内有几个人大家基本都知道,比如说王巍、唐巧,还有YYKit框架的作者现任职于滴滴的郭曜源 - ibireme等。这里有一篇唐巧对他的专访,还有他的 GitHub - Yaoyuan 和 博客,这里贴出来框架YYKit 框架。接下来几篇我们就一起来看一下这个框架。感兴趣的可以看上面写的几篇。
1. YYKit源码探究(一) —— 基本概览
2. YYKit源码探究(二) —— NSString分类之Hash(一)
3. YYKit源码探究(三) —— NSString分类之Encode and decode(二)
4. YYKit源码探究(四) —— NSString分类之Drawing(三)
5. YYKit源码探究(五) —— NSString分类之Regular Expression(四)
6. YYKit源码探究(六) —— NSString分类之NSNumber Compatible(五)
7. YYKit源码探究(七) —— NSString分类之Utilities(六)
8. YYKit源码探究(八) —— NSNumber分类(一)
9. YYKit源码探究(九) —— UIFont分类之架构分析和Font Traits(一)
10. YYKit源码探究(十) —— UIFont分类之Create font(二)
11. YYKit源码探究(十一) —— UIFont分类之Load and unload font(三)
12. YYKit源码探究(十二) —— UIFont分类之Dump font data(四)
13. YYKit源码探究(十三) —— UIImage分类之框架结构和Create image部分(一)
14. YYKit源码探究(十四) —— UIImage分类之Image Info(二)
15. YYKit源码探究(十五) —— UIImage分类之Modify Image(三)
16. YYKit源码探究(十六) —— UIImage分类之Image Effect(四)
17. YYKit源码探究(十七) —— UIImageView分类之架构和image部分(一)
18. YYKit源码探究(十八) —— UIImageView分类之highlight image部分(二)
19. YYKit源码探究(十九) —— UIScreen分类(一)
20. YYKit源码探究(二十) —— UIScrollView分类(一)
21. YYKit源码探究(二十一) —— UITableView分类(一)
22. YYKit源码探究(二十二) —— UITextField分类(一)
23. YYKit源码探究(二十三) —— UIView分类(一)
24. YYKit源码探究(二十四) —— UIPasteboard分类(一)
25. YYKit源码探究(二十五) —— UIGestureRecognizer分类(一)
26. YYKit源码探究(二十六) —— UIDevice分类框架及Device Information(一)
27. YYKit源码探究(二十七) —— UIDevice分类之Network Information(二)
28. YYKit源码探究(二十八) —— UIDevice分类之Disk Space(三)
29. YYKit源码探究(二十九) —— UIDevice分类之Memory Information(四)
30. YYKit源码探究(三十) —— UIDevice分类之CPU Information(五)
31. YYKit源码探究(三十一) —— UIControl分类(一)
32. YYKit源码探究(三十二) —— UIColor分类之Create a UIColor Object(一)
33. YYKit源码探究(三十三) —— UIColor分类之Get color's description(二)
34. YYKit源码探究(三十四) —— UIColor分类之Retrieving Color Information(三)
35. YYKit源码探究(三十五) —— UIButton分类之image(一)
36. YYKit源码探究(三十六) —— UIButton分类之background image(二)
37. YYKit源码探究(三十七) —— UIBezierPath分类(一)
38. YYKit源码探究(三十八) —— UIBarButtonItem分类(一)
39. YYKit源码探究(三十九) —— UIApplication分类(一)
40. YYKit源码探究(四十) —— NSTimer分类(一)
41. YYKit源码探究(四十一) —— NSParagraphStyle分类(一)
42. YYKit源码探究(四十二) —— NSObject分类之YYModel(一)
43. YYKit源码探究(四十三) —— NSObject分类之KVO(二)
44. YYKit源码探究(四十四) —— NSObject分类之Sending messages with variable parameters(三)
45. YYKit源码探究(四十五) —— NSObject分类之Swap method (Swizzling)(四)
46. YYKit源码探究(四十六) —— NSObject分类之Associate value(五)
47. YYKit源码探究(四十七) —— NSObject分类之Other(六)
48. YYKit源码探究(四十八) —— NSNotificationCenter分类(一)
49. YYKit源码探究(四十九) —— NSKeyedUnarchiver分类(一)
50. YYKit源码探究(五十) —— NSDictionary分类之Dictionary Convertor(一)
51. YYKit源码探究(五十一) —— NSDictionary分类之Dictionary Value Getter(二)
52. YYKit源码探究(五十二) —— NSDictionary分类之NSMutableDictionary(三)
53. YYKit源码探究(五十三) —— NSDate分类之Component Properties(一)
54. YYKit源码探究(五十四) —— NSDate分类之Date modify(二)
55. YYKit源码探究(五十五) —— NSDate分类之Date Format(三)
56. YYKit源码探究(五十六) —— NSData分类之Hash(一)
57. YYKit源码探究(五十七) —— NSData分类之Encrypt and Decrypt(二)
58. YYKit源码探究(五十八) —— NSData分类之Encode and decode(三)
59. YYKit源码探究(五十九) —— NSData分类之Inflate and deflate(四)
60. YYKit源码探究(六十) —— NSData分类之Others(五)
61. YYKit源码探究(六十一) —— NSBundle分类(一)
62. YYKit源码探究(六十二) —— NSAttributedString分类之基本(一)
63. YYKit源码探究(六十三) —— NSAttributedString分类之Retrieving character attribute information(二)
64. YYKit源码探究(六十四) —— NSAttributedString分类之Get character attribute as property(三)
回顾
上一篇主要介绍了NSAttributedString
分类的Get character attribute as property
部分,这一篇主要看一下NSAttributedString
分类的Get paragraph attribute as property
部分。
API
下面我们看一下API
/**
The text alignment (A wrapper for NSParagraphStyle). (read-only)
@discussion Natural text alignment is realized as left or right alignment
depending on the line sweep direction of the first script contained in the paragraph.
@discussion Default is NSTextAlignmentNatural.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) NSTextAlignment alignment;
- (NSTextAlignment)alignmentAtIndex:(NSUInteger)index;
/**
The mode that should be used to break lines (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the line break mode to be used laying out the paragraph's text.
@discussion Default is NSLineBreakByWordWrapping.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) NSLineBreakMode lineBreakMode;
- (NSLineBreakMode)lineBreakModeAtIndex:(NSUInteger)index;
/**
The distance in points between the bottom of one line fragment and the top of the next.
(A wrapper for NSParagraphStyle) (read-only)
@discussion This value is always nonnegative. This value is included in the line
fragment heights in the layout manager.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat lineSpacing;
- (CGFloat)lineSpacingAtIndex:(NSUInteger)index;
/**
The space after the end of the paragraph (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the space (measured in points) added at the
end of the paragraph to separate it from the following paragraph. This value must
be nonnegative. The space between paragraphs is determined by adding the previous
paragraph's paragraphSpacing and the current paragraph's paragraphSpacingBefore.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat paragraphSpacing;
- (CGFloat)paragraphSpacingAtIndex:(NSUInteger)index;
/**
The distance between the paragraph's top and the beginning of its text content.
(A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the space (measured in points) between the
paragraph's top and the beginning of its text content.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat paragraphSpacingBefore;
- (CGFloat)paragraphSpacingBeforeAtIndex:(NSUInteger)index;
/**
The indentation of the first line (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the distance (in points) from the leading margin
of a text container to the beginning of the paragraph's first line. This value
is always nonnegative.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat firstLineHeadIndent;
- (CGFloat)firstLineHeadIndentAtIndex:(NSUInteger)index;
/**
The indentation of the receiver's lines other than the first. (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the distance (in points) from the leading margin
of a text container to the beginning of lines other than the first. This value is
always nonnegative.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat headIndent;
- (CGFloat)headIndentAtIndex:(NSUInteger)index;
/**
The trailing indentation (A wrapper for NSParagraphStyle). (read-only)
@discussion If positive, this value is the distance from the leading margin
(for example, the left margin in left-to-right text). If 0 or negative, it's the
distance from the trailing margin.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat tailIndent;
- (CGFloat)tailIndentAtIndex:(NSUInteger)index;
/**
The receiver's minimum height (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the minimum height in points that any line in
the receiver will occupy, regardless of the font size or size of any attached graphic.
This value must be nonnegative.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat minimumLineHeight;
- (CGFloat)minimumLineHeightAtIndex:(NSUInteger)index;
/**
The receiver's maximum line height (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the maximum height in points that any line in
the receiver will occupy, regardless of the font size or size of any attached graphic.
This value is always nonnegative. Glyphs and graphics exceeding this height will
overlap neighboring lines; however, a maximum height of 0 implies no line height limit.
Although this limit applies to the line itself, line spacing adds extra space between adjacent lines.
@discussion Default is 0 (no limit).
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat maximumLineHeight;
- (CGFloat)maximumLineHeightAtIndex:(NSUInteger)index;
/**
The line height multiple (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the line break mode to be used laying out the paragraph's text.
@discussion Default is 0 (no multiple).
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) CGFloat lineHeightMultiple;
- (CGFloat)lineHeightMultipleAtIndex:(NSUInteger)index;
/**
The base writing direction (A wrapper for NSParagraphStyle). (read-only)
@discussion If you specify NSWritingDirectionNaturalDirection, the receiver resolves
the writing direction to either NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
depending on the direction for the user's `language` preference setting.
@discussion Default is NSWritingDirectionNatural.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 YYKit:6.0
*/
@property (nonatomic, readonly) NSWritingDirection baseWritingDirection;
- (NSWritingDirection)baseWritingDirectionAtIndex:(NSUInteger)index;
/**
The paragraph's threshold for hyphenation. (A wrapper for NSParagraphStyle). (read-only)
@discussion Valid values lie between 0.0 and 1.0 inclusive. Hyphenation is attempted
when the ratio of the text width (as broken without hyphenation) to the width of the
line fragment is less than the hyphenation factor. When the paragraph's hyphenation
factor is 0.0, the layout manager's hyphenation factor is used instead. When both
are 0.0, hyphenation is disabled.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since UIKit:6.0
*/
@property (nonatomic, readonly) float hyphenationFactor;
- (float)hyphenationFactorAtIndex:(NSUInteger)index;
/**
The document-wide default tab interval (A wrapper for NSParagraphStyle). (read-only)
@discussion This property represents the default tab interval in points. Tabs after the
last specified in tabStops are placed at integer multiples of this distance (if positive).
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:7.0 UIKit:7.0 YYKit:7.0
*/
@property (nonatomic, readonly) CGFloat defaultTabInterval;
- (CGFloat)defaultTabIntervalAtIndex:(NSUInteger)index;
/**
An array of NSTextTab objects representing the receiver's tab stops.
(A wrapper for NSParagraphStyle). (read-only)
@discussion The NSTextTab objects, sorted by location, define the tab stops for
the paragraph style.
@discussion Default is 12 TabStops with 28.0 tab interval.
@discussion Get this property returns the first character's attribute.
@since CoreText:7.0 UIKit:7.0 YYKit:7.0
*/
@property (nullable, nonatomic, copy, readonly) NSArray<NSTextTab *> *tabStops;
- (nullable NSArray<NSTextTab *> *)tabStopsAtIndex:(NSUInteger)index;
下面我们详细的看一下。
1. @property (nonatomic, readonly) NSTextAlignment alignment; 和 - (NSTextAlignment)alignmentAtIndex:(NSUInteger)index;
该属性的作用就是文本对齐方式。(A wrapper for NSParagraphStyle)
。
根据段落中包含的第一个脚本的行扫描方向,文本对齐被实现为左对齐或右对齐。默认的对齐方式是NSTextAlignmentNatural
。
方法实现
- (NSTextAlignment)alignment {
ParagraphAttribute(alignment);
}
#define ParagraphAttribute(_attr_) \
NSParagraphStyle *style = self.paragraphStyle; \
if (!style) style = [NSParagraphStyle defaultParagraphStyle]; \
return style. _attr_;
- (NSTextAlignment)alignmentAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(alignment);
}
#define ParagraphAttributeAtIndex(_attr_) \
NSParagraphStyle *style = [self paragraphStyleAtIndex:index]; \
if (!style) style = [NSParagraphStyle defaultParagraphStyle]; \
return style. _attr_;
2. @property (nonatomic, readonly) NSLineBreakMode lineBreakMode; 和 - (NSLineBreakMode)lineBreakModeAtIndex:(NSUInteger)index;
应该用于分行的模式(NSParagraphStyle
的包装)。 (只读),该属性包含用于布置段落文本的换行符模式,默认是NSLineBreakByWordWrapping
。
方法实现
- (NSLineBreakMode)lineBreakMode {
ParagraphAttribute(lineBreakMode);
}
- (NSLineBreakMode)lineBreakModeAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(lineBreakMode);
}
3. @property (nonatomic, readonly) CGFloat lineSpacing; 和 - (CGFloat)lineSpacingAtIndex:(NSUInteger)index;
该组的作用获取就是一个线段底部与下一个线段顶部之间的距离。该值永远是非负的,该值包含在布局管理器中的线段高度中。
方法实现
- (CGFloat)lineSpacing {
ParagraphAttribute(lineSpacing);
}
- (CGFloat)lineSpacingAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(lineSpacing);
}
4. @property (nonatomic, readonly) CGFloat paragraphSpacing; 和 - (CGFloat)paragraphSpacingAtIndex:(NSUInteger)index;
段落结束后的空格(NSParagraphStyle
的包装),只读。
该属性包含段落末尾添加的空间(以点为单位),以将其与以下段落分开。 这个值必须是非负的。 段落之间的空间通过添加前一段的段落空间和当前段落的段落空间来确定。默认值为0。
方法实现
- (CGFloat)paragraphSpacing {
ParagraphAttribute(paragraphSpacing);
}
- (CGFloat)paragraphSpacingAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(paragraphSpacing);
}
5. @property (nonatomic, readonly) CGFloat paragraphSpacingBefore; 和 - (CGFloat)paragraphSpacingBeforeAtIndex:(NSUInteger)index;
段落顶部与其文本内容开始之间的距离,(NSParagraphStyle
的包装器),只读。此属性包含段落顶部与其文本内容开头之间的空间(以点为单位),默认值为0。
方法实现
- (CGFloat)paragraphSpacingBefore {
ParagraphAttribute(paragraphSpacingBefore);
}
- (CGFloat)paragraphSpacingBeforeAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(paragraphSpacingBefore);
}
6. @property (nonatomic, readonly) CGFloat firstLineHeadIndent; 和 - (CGFloat)firstLineHeadIndentAtIndex:(NSUInteger)index;
第一行的缩进(NSParagraphStyle
的包装), (只读)。此属性包含从文本容器的前导边距到段落第一行开头的距离(以点为单位),这个值总是非负的,默认值为0。
方法实现
- (CGFloat)firstLineHeadIndent {
ParagraphAttribute(firstLineHeadIndent);
}
- (CGFloat)firstLineHeadIndentAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(firstLineHeadIndent);
}
7. @property (nonatomic, readonly) CGFloat headIndent; 和 - (CGFloat)headIndentAtIndex:(NSUInteger)index;
除第一个以外的receiver行的缩进,(NSParagraphStyle
的包装器),(只读)。该属性包含从文本容器的前导边距到除第一个行之外的行的起始位置的距离(以点为单位),这个值总是非负的。默认值为0。
方法实现
- (CGFloat)headIndent {
ParagraphAttribute(headIndent);
}
- (CGFloat)headIndentAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(headIndent);
}
8. @property (nonatomic, readonly) CGFloat tailIndent; 和 - (CGFloat)tailIndentAtIndex:(NSUInteger)index;
尾部缩进(NSParagraphStyle
的包装),(只读)。如果为正数,则此值为距前边距的距离(例如,从左到右文本中的左边距)。 如果为0或负值,则表示距尾端距离。默认值为0。
方法实现
- (CGFloat)tailIndent {
ParagraphAttribute(tailIndent);
}
- (CGFloat)tailIndentAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(tailIndent);
}
9. @property (nonatomic, readonly) CGFloat minimumLineHeight; 和 - (CGFloat)minimumLineHeightAtIndex:(NSUInteger)index;
receiver的最小高度,NSParagraphStyle
的封装,只读属性。无论任何附加图形的字体大小或大小,此属性都包含接收器中任何行将占用的点数的最小高度。 这个值必须是非负的,默认值为0。
方法实现
- (CGFloat)minimumLineHeight {
ParagraphAttribute(minimumLineHeight);
}
- (CGFloat)minimumLineHeightAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(minimumLineHeight);
}
10. @property (nonatomic, readonly) CGFloat maximumLineHeight; 和 - (CGFloat)maximumLineHeightAtIndex:(NSUInteger)index;
该组的作用就是receiver最大行高,NSParagraphStyle
的封装,只读的。
无论任何附加图形的字体大小或大小如何,该属性都包含接收器中任何行将占用的最大点数。 这个值总是非负的。 超过此高度的字形和图形将与相邻行重叠;然而,最大高度为0意味着没有线高度限制。 虽然此限制适用于行本身,但行间距会在相邻行之间增加额外的空间。
方法实现
- (CGFloat)maximumLineHeight {
ParagraphAttribute(maximumLineHeight);
}
- (CGFloat)maximumLineHeightAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(maximumLineHeight);
}
11. @property (nonatomic, readonly) CGFloat lineHeightMultiple; 和 - (CGFloat)lineHeightMultipleAtIndex:(NSUInteger)index;
该组是获取行高倍数,NSParagraphStyle
的封装,只读属性。默认值是0。
该属性包含用于布置段落文本的换行符模式。
方法实现
- (CGFloat)lineHeightMultiple {
ParagraphAttribute(lineHeightMultiple);
}
- (CGFloat)lineHeightMultipleAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(lineHeightMultiple);
}
12. @property (nonatomic, readonly) NSWritingDirection baseWritingDirection; 和 - (NSWritingDirection)baseWritingDirectionAtIndex:(NSUInteger)index;
该组的作用就是基本书写方向,NSParagraphStyle
的封装,只读属性。默认值是NSWritingDirectionNatural
。
如果指定NSWritingDirectionNaturalDirection
,则接收方将写入方向解析为NSWritingDirectionLeftToRight
或NSWritingDirectionRightToLeft
,具体取决于用户language
偏好设置的方向。
方法实现
- (NSWritingDirection)baseWritingDirection {
ParagraphAttribute(baseWritingDirection);
}
- (NSWritingDirection)baseWritingDirectionAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(baseWritingDirection);
}
13. @property (nonatomic, readonly) float hyphenationFactor; 和 - (float)hyphenationFactorAtIndex:(NSUInteger)index;
该组获取该段落的hyphenation
阈值,默认值为0,只读属性,NSParagraphStyle
的封装。
有效值介于0.0和1.0之间。 当文本宽度(如果没有连字符断开)与行宽度的比率小于hyphenation
因子,则尝试进行连字。 当段落的连字因子为0.0时,将使用布局管理器的连字因子。 当两者均为0.0时,连字符被禁用。
方法实现
- (float)hyphenationFactor {
ParagraphAttribute(hyphenationFactor);
}
- (float)hyphenationFactorAtIndex:(NSUInteger)index {
ParagraphAttributeAtIndex(hyphenationFactor);
}
14. @property (nonatomic, readonly) CGFloat defaultTabInterval; 和 - (CGFloat)defaultTabIntervalAtIndex:(NSUInteger)index;
该组获取文档宽度的默认tab间隔,NSParagraphStyle的封装,只读属性,默认值为0。
该属性表示默认的tab间隔(以点为单位)。 tabStops中指定的最后一个tab位于此距离的整数倍(如果为正数)。
方法实现
- (CGFloat)defaultTabInterval {
if (!kiOS7Later) return 0;
ParagraphAttribute(defaultTabInterval);
}
- (CGFloat)defaultTabIntervalAtIndex:(NSUInteger)index {
if (!kiOS7Later) return 0;
ParagraphAttributeAtIndex(defaultTabInterval);
}
15. @property (nullable, nonatomic, copy, readonly) NSArray<NSTextTab *> *tabStops; 和 - (nullable NSArray<NSTextTab *> *)tabStopsAtIndex:(NSUInteger)index;
该组的作用就是获取表示receiver
的tab stops
的NSTextTab
对象数组。NSParagraphStyle
的封装,只读属性。默认值是12 TabStops,28.0 tab
间隔。
按位置排序的NSTextTa
b对象为段落样式定义了制表位。
方法实现
- (NSArray *)tabStops {
if (!kiOS7Later) return nil;
ParagraphAttribute(tabStops);
}
- (NSArray *)tabStopsAtIndex:(NSUInteger)index {
if (!kiOS7Later) return nil;
ParagraphAttributeAtIndex(tabStops);
}
后记
本篇主要讲述了 NSAttributedString分类之Get paragraph attribute as property,感兴趣的给个赞或者关注~~~~