NSAttributedString+YYText.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. //
  2. // NSAttributedString+YYText.h
  3. // YYText <https://github.com/ibireme/YYText>
  4. //
  5. // Created by ibireme on 14/10/7.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #import <CoreText/CoreText.h>
  13. #if __has_include(<YYText/YYText.h>)
  14. #import <YYText/YYTextAttribute.h>
  15. #import <YYText/YYTextRubyAnnotation.h>
  16. #else
  17. #import "YYTextAttribute.h"
  18. #import "YYTextRubyAnnotation.h"
  19. #endif
  20. /**
  21. Get pre-defined attributes from attributed string.
  22. All properties defined in UIKit, CoreText and YYText are included.
  23. */
  24. @interface NSAttributedString (YYText)
  25. /**
  26. Archive the string to data.
  27. @return Returns nil if an error occurs.
  28. */
  29. - (NSData *)yy_archiveToData;
  30. /**
  31. Unarchive string from data.
  32. @param data The archived attributed string data.
  33. @return Returns nil if an error occurs.
  34. */
  35. + (instancetype)yy_unarchiveFromData:(NSData *)data;
  36. #pragma mark - Retrieving character attribute information
  37. ///=============================================================================
  38. /// @name Retrieving character attribute information
  39. ///=============================================================================
  40. /**
  41. Returns the attributes at first charactor.
  42. */
  43. @property (nonatomic, copy, readonly) NSDictionary *yy_attributes;
  44. /**
  45. Returns the attributes for the character at a given index.
  46. @discussion Raises an `NSRangeException` if index lies beyond the end of the
  47. receiver's characters.
  48. @param index The index for which to return attributes.
  49. This value must lie within the bounds of the receiver.
  50. @return The attributes for the character at index.
  51. */
  52. - (NSDictionary *)yy_attributesAtIndex:(NSUInteger)index;
  53. /**
  54. Returns the value for an attribute with a given name of the character at a given index.
  55. @discussion Raises an `NSRangeException` if index lies beyond the end of the
  56. receiver's characters.
  57. @param attributeName The name of an attribute.
  58. @param index The index for which to return attributes.
  59. This value must not exceed the bounds of the receiver.
  60. @return The value for the attribute named `attributeName` of the character at
  61. index `index`, or nil if there is no such attribute.
  62. */
  63. - (id)yy_attribute:(NSString *)attributeName atIndex:(NSUInteger)index;
  64. #pragma mark - Get character attribute as property
  65. ///=============================================================================
  66. /// @name Get character attribute as property
  67. ///=============================================================================
  68. /**
  69. The font of the text. (read-only)
  70. @discussion Default is Helvetica (Neue) 12.
  71. @discussion Get this property returns the first character's attribute.
  72. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  73. */
  74. @property (nonatomic, strong, readonly) UIFont *yy_font;
  75. - (UIFont *)yy_fontAtIndex:(NSUInteger)index;
  76. /**
  77. A kerning adjustment. (read-only)
  78. @discussion Default is standard kerning. The kerning attribute indicate how many
  79. points the following character should be shifted from its default offset as
  80. defined by the current character's font in points; a positive kern indicates a
  81. shift farther along and a negative kern indicates a shift closer to the current
  82. character. If this attribute is not present, standard kerning will be used.
  83. If this attribute is set to 0.0, no kerning will be done at all.
  84. @discussion Get this property returns the first character's attribute.
  85. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  86. */
  87. @property (nonatomic, strong, readonly) NSNumber *yy_kern;
  88. - (NSNumber *)yy_kernAtIndex:(NSUInteger)index;
  89. /**
  90. The foreground color. (read-only)
  91. @discussion Default is Black.
  92. @discussion Get this property returns the first character's attribute.
  93. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  94. */
  95. @property (nonatomic, strong, readonly) UIColor *yy_color;
  96. - (UIColor *)yy_colorAtIndex:(NSUInteger)index;
  97. /**
  98. The background color. (read-only)
  99. @discussion Default is nil (or no background).
  100. @discussion Get this property returns the first character's attribute.
  101. @since UIKit:6.0
  102. */
  103. @property (nonatomic, strong, readonly) UIColor *yy_backgroundColor;
  104. - (UIColor *)yy_backgroundColorAtIndex:(NSUInteger)index;
  105. /**
  106. The stroke width. (read-only)
  107. @discussion Default value is 0.0 (no stroke). This attribute, interpreted as
  108. a percentage of font point size, controls the text drawing mode: positive
  109. values effect drawing with stroke only; negative values are for stroke and fill.
  110. A typical value for outlined text is 3.0.
  111. @discussion Get this property returns the first character's attribute.
  112. @since CoreText:3.2 UIKit:6.0
  113. */
  114. @property (nonatomic, strong, readonly) NSNumber *yy_strokeWidth;
  115. - (NSNumber *)yy_strokeWidthAtIndex:(NSUInteger)index;
  116. /**
  117. The stroke color. (read-only)
  118. @discussion Default value is nil (same as foreground color).
  119. @discussion Get this property returns the first character's attribute.
  120. @since CoreText:3.2 UIKit:6.0
  121. */
  122. @property (nonatomic, strong, readonly) UIColor *yy_strokeColor;
  123. - (UIColor *)yy_strokeColorAtIndex:(NSUInteger)index;
  124. /**
  125. The text shadow. (read-only)
  126. @discussion Default value is nil (no shadow).
  127. @discussion Get this property returns the first character's attribute.
  128. @since UIKit:6.0 YYText:6.0
  129. */
  130. @property (nonatomic, strong, readonly) NSShadow *yy_shadow;
  131. - (NSShadow *)yy_shadowAtIndex:(NSUInteger)index;
  132. /**
  133. The strikethrough style. (read-only)
  134. @discussion Default value is NSUnderlineStyleNone (no strikethrough).
  135. @discussion Get this property returns the first character's attribute.
  136. @since UIKit:6.0
  137. */
  138. @property (nonatomic, assign, readonly) NSUnderlineStyle yy_strikethroughStyle;
  139. - (NSUnderlineStyle)yy_strikethroughStyleAtIndex:(NSUInteger)index;
  140. /**
  141. The strikethrough color. (read-only)
  142. @discussion Default value is nil (same as foreground color).
  143. @discussion Get this property returns the first character's attribute.
  144. @since UIKit:7.0
  145. */
  146. @property (nonatomic, strong, readonly) UIColor *yy_strikethroughColor;
  147. - (UIColor *)yy_strikethroughColorAtIndex:(NSUInteger)index;
  148. /**
  149. The underline style. (read-only)
  150. @discussion Default value is NSUnderlineStyleNone (no underline).
  151. @discussion Get this property returns the first character's attribute.
  152. @since CoreText:3.2 UIKit:6.0
  153. */
  154. @property (nonatomic, assign, readonly) NSUnderlineStyle yy_underlineStyle;
  155. - (NSUnderlineStyle)yy_underlineStyleAtIndex:(NSUInteger)index;
  156. /**
  157. The underline color. (read-only)
  158. @discussion Default value is nil (same as foreground color).
  159. @discussion Get this property returns the first character's attribute.
  160. @since CoreText:3.2 UIKit:7.0
  161. */
  162. @property (nonatomic, strong, readonly) UIColor *yy_underlineColor;
  163. - (UIColor *)yy_underlineColorAtIndex:(NSUInteger)index;
  164. /**
  165. Ligature formation control. (read-only)
  166. @discussion Default is int value 1. The ligature attribute determines what kinds
  167. of ligatures should be used when displaying the string. A value of 0 indicates
  168. that only ligatures essential for proper rendering of text should be used,
  169. 1 indicates that standard ligatures should be used, and 2 indicates that all
  170. available ligatures should be used. Which ligatures are standard depends on the
  171. script and possibly the font.
  172. @discussion Get this property returns the first character's attribute.
  173. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  174. */
  175. @property (nonatomic, strong, readonly) NSNumber *yy_ligature;
  176. - (NSNumber *)yy_ligatureAtIndex:(NSUInteger)index;
  177. /**
  178. The text effect. (read-only)
  179. @discussion Default is nil (no effect). The only currently supported value
  180. is NSTextEffectLetterpressStyle.
  181. @discussion Get this property returns the first character's attribute.
  182. @since UIKit:7.0
  183. */
  184. @property (nonatomic, strong, readonly) NSString *yy_textEffect;
  185. - (NSString *)yy_textEffectAtIndex:(NSUInteger)index;
  186. /**
  187. The skew to be applied to glyphs. (read-only)
  188. @discussion Default is 0 (no skew).
  189. @discussion Get this property returns the first character's attribute.
  190. @since UIKit:7.0
  191. */
  192. @property (nonatomic, strong, readonly) NSNumber *yy_obliqueness;
  193. - (NSNumber *)yy_obliquenessAtIndex:(NSUInteger)index;
  194. /**
  195. The log of the expansion factor to be applied to glyphs. (read-only)
  196. @discussion Default is 0 (no expansion).
  197. @discussion Get this property returns the first character's attribute.
  198. @since UIKit:7.0
  199. */
  200. @property (nonatomic, strong, readonly) NSNumber *yy_expansion;
  201. - (NSNumber *)yy_expansionAtIndex:(NSUInteger)index;
  202. /**
  203. The character's offset from the baseline, in points. (read-only)
  204. @discussion Default is 0.
  205. @discussion Get this property returns the first character's attribute.
  206. @since UIKit:7.0
  207. */
  208. @property (nonatomic, strong, readonly) NSNumber *yy_baselineOffset;
  209. - (NSNumber *)yy_baselineOffsetAtIndex:(NSUInteger)index;
  210. /**
  211. Glyph orientation control. (read-only)
  212. @discussion Default is NO. A value of NO indicates that horizontal glyph forms
  213. are to be used, YES indicates that vertical glyph forms are to be used.
  214. @discussion Get this property returns the first character's attribute.
  215. @since CoreText:4.3 YYText:6.0
  216. */
  217. @property (nonatomic, assign, readonly) BOOL yy_verticalGlyphForm;
  218. - (BOOL)yy_verticalGlyphFormAtIndex:(NSUInteger)index;
  219. /**
  220. Specifies text language. (read-only)
  221. @discussion Value must be a NSString containing a locale identifier. Default is
  222. unset. When this attribute is set to a valid identifier, it will be used to select
  223. localized glyphs (if supported by the font) and locale-specific line breaking rules.
  224. @discussion Get this property returns the first character's attribute.
  225. @since CoreText:7.0 YYText:7.0
  226. */
  227. @property (nonatomic, strong, readonly) NSString *yy_language;
  228. - (NSString *)yy_languageAtIndex:(NSUInteger)index;
  229. /**
  230. Specifies a bidirectional override or embedding. (read-only)
  231. @discussion See alse NSWritingDirection and NSWritingDirectionAttributeName.
  232. @discussion Get this property returns the first character's attribute.
  233. @since CoreText:6.0 UIKit:7.0 YYText:6.0
  234. */
  235. @property (nonatomic, strong, readonly) NSArray *yy_writingDirection;
  236. - (NSArray *)yy_writingDirectionAtIndex:(NSUInteger)index;
  237. /**
  238. An NSParagraphStyle object which is used to specify things like
  239. line alignment, tab rulers, writing direction, etc. (read-only)
  240. @discussion Default is nil ([NSParagraphStyle defaultParagraphStyle]).
  241. @discussion Get this property returns the first character's attribute.
  242. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  243. */
  244. @property (nonatomic, strong, readonly) NSParagraphStyle *yy_paragraphStyle;
  245. - (NSParagraphStyle *)yy_paragraphStyleAtIndex:(NSUInteger)index;
  246. #pragma mark - Get paragraph attribute as property
  247. ///=============================================================================
  248. /// @name Get paragraph attribute as property
  249. ///=============================================================================
  250. /**
  251. The text alignment (A wrapper for NSParagraphStyle). (read-only)
  252. @discussion Natural text alignment is realized as left or right alignment
  253. depending on the line sweep direction of the first script contained in the paragraph.
  254. @discussion Default is NSTextAlignmentNatural.
  255. @discussion Get this property returns the first character's attribute.
  256. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  257. */
  258. @property (nonatomic, assign, readonly) NSTextAlignment yy_alignment;
  259. - (NSTextAlignment)yy_alignmentAtIndex:(NSUInteger)index;
  260. /**
  261. The mode that should be used to break lines (A wrapper for NSParagraphStyle). (read-only)
  262. @discussion This property contains the line break mode to be used laying out the paragraph's text.
  263. @discussion Default is NSLineBreakByWordWrapping.
  264. @discussion Get this property returns the first character's attribute.
  265. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  266. */
  267. @property (nonatomic, assign, readonly) NSLineBreakMode yy_lineBreakMode;
  268. - (NSLineBreakMode)yy_lineBreakModeAtIndex:(NSUInteger)index;
  269. /**
  270. The distance in points between the bottom of one line fragment and the top of the next.
  271. (A wrapper for NSParagraphStyle) (read-only)
  272. @discussion This value is always nonnegative. This value is included in the line
  273. fragment heights in the layout manager.
  274. @discussion Default is 0.
  275. @discussion Get this property returns the first character's attribute.
  276. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  277. */
  278. @property (nonatomic, assign, readonly) CGFloat yy_lineSpacing;
  279. - (CGFloat)yy_lineSpacingAtIndex:(NSUInteger)index;
  280. /**
  281. The space after the end of the paragraph (A wrapper for NSParagraphStyle). (read-only)
  282. @discussion This property contains the space (measured in points) added at the
  283. end of the paragraph to separate it from the following paragraph. This value must
  284. be nonnegative. The space between paragraphs is determined by adding the previous
  285. paragraph's paragraphSpacing and the current paragraph's paragraphSpacingBefore.
  286. @discussion Default is 0.
  287. @discussion Get this property returns the first character's attribute.
  288. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  289. */
  290. @property (nonatomic, assign, readonly) CGFloat yy_paragraphSpacing;
  291. - (CGFloat)yy_paragraphSpacingAtIndex:(NSUInteger)index;
  292. /**
  293. The distance between the paragraph's top and the beginning of its text content.
  294. (A wrapper for NSParagraphStyle). (read-only)
  295. @discussion This property contains the space (measured in points) between the
  296. paragraph's top and the beginning of its text content.
  297. @discussion Default is 0.
  298. @discussion Get this property returns the first character's attribute.
  299. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  300. */
  301. @property (nonatomic, assign, readonly) CGFloat yy_paragraphSpacingBefore;
  302. - (CGFloat)yy_paragraphSpacingBeforeAtIndex:(NSUInteger)index;
  303. /**
  304. The indentation of the first line (A wrapper for NSParagraphStyle). (read-only)
  305. @discussion This property contains the distance (in points) from the leading margin
  306. of a text container to the beginning of the paragraph's first line. This value
  307. is always nonnegative.
  308. @discussion Default is 0.
  309. @discussion Get this property returns the first character's attribute.
  310. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  311. */
  312. @property (nonatomic, assign, readonly) CGFloat yy_firstLineHeadIndent;
  313. - (CGFloat)yy_firstLineHeadIndentAtIndex:(NSUInteger)index;
  314. /**
  315. The indentation of the receiver's lines other than the first. (A wrapper for NSParagraphStyle). (read-only)
  316. @discussion This property contains the distance (in points) from the leading margin
  317. of a text container to the beginning of lines other than the first. This value is
  318. always nonnegative.
  319. @discussion Default is 0.
  320. @discussion Get this property returns the first character's attribute.
  321. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  322. */
  323. @property (nonatomic, assign, readonly) CGFloat yy_headIndent;
  324. - (CGFloat)yy_headIndentAtIndex:(NSUInteger)index;
  325. /**
  326. The trailing indentation (A wrapper for NSParagraphStyle). (read-only)
  327. @discussion If positive, this value is the distance from the leading margin
  328. (for example, the left margin in left-to-right text). If 0 or negative, it's the
  329. distance from the trailing margin.
  330. @discussion Default is 0.
  331. @discussion Get this property returns the first character's attribute.
  332. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  333. */
  334. @property (nonatomic, assign, readonly) CGFloat yy_tailIndent;
  335. - (CGFloat)yy_tailIndentAtIndex:(NSUInteger)index;
  336. /**
  337. The receiver's minimum height (A wrapper for NSParagraphStyle). (read-only)
  338. @discussion This property contains the minimum height in points that any line in
  339. the receiver will occupy, regardless of the font size or size of any attached graphic.
  340. This value must be nonnegative.
  341. @discussion Default is 0.
  342. @discussion Get this property returns the first character's attribute.
  343. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  344. */
  345. @property (nonatomic, assign, readonly) CGFloat yy_minimumLineHeight;
  346. - (CGFloat)yy_minimumLineHeightAtIndex:(NSUInteger)index;
  347. /**
  348. The receiver's maximum line height (A wrapper for NSParagraphStyle). (read-only)
  349. @discussion This property contains the maximum height in points that any line in
  350. the receiver will occupy, regardless of the font size or size of any attached graphic.
  351. This value is always nonnegative. Glyphs and graphics exceeding this height will
  352. overlap neighboring lines; however, a maximum height of 0 implies no line height limit.
  353. Although this limit applies to the line itself, line spacing adds extra space between adjacent lines.
  354. @discussion Default is 0 (no limit).
  355. @discussion Get this property returns the first character's attribute.
  356. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  357. */
  358. @property (nonatomic, assign, readonly) CGFloat yy_maximumLineHeight;
  359. - (CGFloat)yy_maximumLineHeightAtIndex:(NSUInteger)index;
  360. /**
  361. The line height multiple (A wrapper for NSParagraphStyle). (read-only)
  362. @discussion This property contains the line break mode to be used laying out the paragraph's text.
  363. @discussion Default is 0 (no multiple).
  364. @discussion Get this property returns the first character's attribute.
  365. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  366. */
  367. @property (nonatomic, assign, readonly) CGFloat yy_lineHeightMultiple;
  368. - (CGFloat)yy_lineHeightMultipleAtIndex:(NSUInteger)index;
  369. /**
  370. The base writing direction (A wrapper for NSParagraphStyle). (read-only)
  371. @discussion If you specify NSWritingDirectionNaturalDirection, the receiver resolves
  372. the writing direction to either NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
  373. depending on the direction for the user's `language` preference setting.
  374. @discussion Default is NSWritingDirectionNatural.
  375. @discussion Get this property returns the first character's attribute.
  376. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  377. */
  378. @property (nonatomic, assign, readonly) NSWritingDirection yy_baseWritingDirection;
  379. - (NSWritingDirection)yy_baseWritingDirectionAtIndex:(NSUInteger)index;
  380. /**
  381. The paragraph's threshold for hyphenation. (A wrapper for NSParagraphStyle). (read-only)
  382. @discussion Valid values lie between 0.0 and 1.0 inclusive. Hyphenation is attempted
  383. when the ratio of the text width (as broken without hyphenation) to the width of the
  384. line fragment is less than the hyphenation factor. When the paragraph's hyphenation
  385. factor is 0.0, the layout manager's hyphenation factor is used instead. When both
  386. are 0.0, hyphenation is disabled.
  387. @discussion Default is 0.
  388. @discussion Get this property returns the first character's attribute.
  389. @since UIKit:6.0
  390. */
  391. @property (nonatomic, assign, readonly) float yy_hyphenationFactor;
  392. - (float)yy_hyphenationFactorAtIndex:(NSUInteger)index;
  393. /**
  394. The document-wide default tab interval (A wrapper for NSParagraphStyle). (read-only)
  395. @discussion This property represents the default tab interval in points. Tabs after the
  396. last specified in tabStops are placed at integer multiples of this distance (if positive).
  397. @discussion Default is 0.
  398. @discussion Get this property returns the first character's attribute.
  399. @since CoreText:7.0 UIKit:7.0 YYText:7.0
  400. */
  401. @property (nonatomic, assign, readonly) CGFloat yy_defaultTabInterval;
  402. - (CGFloat)yy_defaultTabIntervalAtIndex:(NSUInteger)index;
  403. /**
  404. An array of NSTextTab objects representing the receiver's tab stops.
  405. (A wrapper for NSParagraphStyle). (read-only)
  406. @discussion The NSTextTab objects, sorted by location, define the tab stops for
  407. the paragraph style.
  408. @discussion Default is 12 TabStops with 28.0 tab interval.
  409. @discussion Get this property returns the first character's attribute.
  410. @since CoreText:7.0 UIKit:7.0 YYText:7.0
  411. */
  412. @property (nonatomic, copy, readonly) NSArray *yy_tabStops;
  413. - (NSArray *)yy_tabStopsAtIndex:(NSUInteger)index;
  414. #pragma mark - Get YYText attribute as property
  415. ///=============================================================================
  416. /// @name Get YYText attribute as property
  417. ///=============================================================================
  418. /**
  419. The text shadow. (read-only)
  420. @discussion Default value is nil (no shadow).
  421. @discussion Get this property returns the first character's attribute.
  422. @since YYText:6.0
  423. */
  424. @property (nonatomic, strong, readonly) YYTextShadow *yy_textShadow;
  425. - (YYTextShadow *)yy_textShadowAtIndex:(NSUInteger)index;
  426. /**
  427. The text inner shadow. (read-only)
  428. @discussion Default value is nil (no shadow).
  429. @discussion Get this property returns the first character's attribute.
  430. @since YYText:6.0
  431. */
  432. @property (nonatomic, strong, readonly) YYTextShadow *yy_textInnerShadow;
  433. - (YYTextShadow *)yy_textInnerShadowAtIndex:(NSUInteger)index;
  434. /**
  435. The text underline. (read-only)
  436. @discussion Default value is nil (no underline).
  437. @discussion Get this property returns the first character's attribute.
  438. @since YYText:6.0
  439. */
  440. @property (nonatomic, strong, readonly) YYTextDecoration *yy_textUnderline;
  441. - (YYTextDecoration *)yy_textUnderlineAtIndex:(NSUInteger)index;
  442. /**
  443. The text strikethrough. (read-only)
  444. @discussion Default value is nil (no strikethrough).
  445. @discussion Get this property returns the first character's attribute.
  446. @since YYText:6.0
  447. */
  448. @property (nonatomic, strong, readonly) YYTextDecoration *yy_textStrikethrough;
  449. - (YYTextDecoration *)yy_textStrikethroughAtIndex:(NSUInteger)index;
  450. /**
  451. The text border. (read-only)
  452. @discussion Default value is nil (no border).
  453. @discussion Get this property returns the first character's attribute.
  454. @since YYText:6.0
  455. */
  456. @property (nonatomic, strong, readonly) YYTextBorder *yy_textBorder;
  457. - (YYTextBorder *)yy_textBorderAtIndex:(NSUInteger)index;
  458. /**
  459. The text background border. (read-only)
  460. @discussion Default value is nil (no background border).
  461. @discussion Get this property returns the first character's attribute.
  462. @since YYText:6.0
  463. */
  464. @property (nonatomic, strong, readonly) YYTextBorder *yy_textBackgroundBorder;
  465. - (YYTextBorder *)yy_textBackgroundBorderAtIndex:(NSUInteger)index;
  466. /**
  467. The glyph transform. (read-only)
  468. @discussion Default value is CGAffineTransformIdentity (no transform).
  469. @discussion Get this property returns the first character's attribute.
  470. @since YYText:6.0
  471. */
  472. @property (nonatomic, assign, readonly) CGAffineTransform yy_textGlyphTransform;
  473. - (CGAffineTransform)yy_textGlyphTransformAtIndex:(NSUInteger)index;
  474. #pragma mark - Query for YYText
  475. ///=============================================================================
  476. /// @name Query for YYText
  477. ///=============================================================================
  478. /**
  479. Returns the plain text from a range.
  480. If there's `YYTextBackedStringAttributeName` attribute, the backed string will
  481. replace the attributed string range.
  482. @param range A range in receiver.
  483. @return The plain text.
  484. */
  485. - (NSString *)yy_plainTextForRange:(NSRange)range;
  486. #pragma mark - Create attachment string for YYText
  487. ///=============================================================================
  488. /// @name Create attachment string for YYText
  489. ///=============================================================================
  490. /**
  491. Creates and returns an attachment.
  492. @param content The attachment (UIImage/UIView/CALayer).
  493. @param contentMode The attachment's content mode.
  494. @param width The attachment's container width in layout.
  495. @param ascent The attachment's container ascent in layout.
  496. @param descent The attachment's container descent in layout.
  497. @return An attributed string, or nil if an error occurs.
  498. @since YYText:6.0
  499. */
  500. + (NSMutableAttributedString *)yy_attachmentStringWithContent:(id)content
  501. contentMode:(UIViewContentMode)contentMode
  502. width:(CGFloat)width
  503. ascent:(CGFloat)ascent
  504. descent:(CGFloat)descent;
  505. /**
  506. Creates and returns an attachment.
  507. Example: ContentMode:bottom Alignment:Top.
  508. The text The attachment holder
  509. ↓ ↓
  510. ─────────┌──────────────────────┐───────
  511. / \ │ │ / ___|
  512. / _ \ │ │| |
  513. / ___ \ │ │| |___ ←── The text line
  514. /_/ \_\│ ██████████████ │ \____|
  515. ─────────│ ██████████████ │───────
  516. │ ██████████████ │
  517. │ ██████████████ ←───────────────── The attachment content
  518. │ ██████████████ │
  519. └──────────────────────┘
  520. @param content The attachment (UIImage/UIView/CALayer).
  521. @param contentMode The attachment's content mode in attachment holder
  522. @param attachmentSize The attachment holder's size in text layout.
  523. @param fontSize The attachment will align to this font.
  524. @param alignment The attachment holder's alignment to text line.
  525. @return An attributed string, or nil if an error occurs.
  526. @since YYText:6.0
  527. */
  528. + (NSMutableAttributedString *)yy_attachmentStringWithContent:(id)content
  529. contentMode:(UIViewContentMode)contentMode
  530. attachmentSize:(CGSize)attachmentSize
  531. alignToFont:(UIFont *)font
  532. alignment:(YYTextVerticalAlignment)alignment;
  533. /**
  534. Creates and returns an attahment from a fourquare image as if it was an emoji.
  535. @param image A fourquare image.
  536. @param fontSize The font size.
  537. @return An attributed string, or nil if an error occurs.
  538. @since YYText:6.0
  539. */
  540. + (NSMutableAttributedString *)yy_attachmentStringWithEmojiImage:(UIImage *)image
  541. fontSize:(CGFloat)fontSize;
  542. #pragma mark - Utility
  543. ///=============================================================================
  544. /// @name Utility
  545. ///=============================================================================
  546. /**
  547. Returns NSMakeRange(0, self.length).
  548. */
  549. - (NSRange)yy_rangeOfAll;
  550. /**
  551. If YES, it share the same attribute in entire text range.
  552. */
  553. - (BOOL)yy_isSharedAttributesInAllRange;
  554. /**
  555. If YES, it can be drawn with the [drawWithRect:options:context:] method or displayed with UIKit.
  556. If NO, it should be drawn with CoreText or YYText.
  557. @discussion If the method returns NO, it means that there's at least one attribute
  558. which is not supported by UIKit (such as CTParagraphStyleRef). If display this string
  559. in UIKit, it may lose some attribute, or even crash the app.
  560. */
  561. - (BOOL)yy_canDrawWithUIKit;
  562. @end
  563. /**
  564. Set pre-defined attributes to attributed string.
  565. All properties defined in UIKit, CoreText and YYText are included.
  566. */
  567. @interface NSMutableAttributedString (YYText)
  568. #pragma mark - Set character attribute
  569. ///=============================================================================
  570. /// @name Set character attribute
  571. ///=============================================================================
  572. /**
  573. Sets the attributes to the entire text string.
  574. @discussion The old attributes will be removed.
  575. @param attributes A dictionary containing the attributes to set, or nil to remove all attributes.
  576. */
  577. - (void)yy_setAttributes:(NSDictionary *)attributes;
  578. - (void)setYy_attributes:(NSDictionary *)attributes;
  579. /**
  580. Sets an attribute with the given name and value to the entire text string.
  581. @param name A string specifying the attribute name.
  582. @param value The attribute value associated with name. Pass `nil` or `NSNull` to
  583. remove the attribute.
  584. */
  585. - (void)yy_setAttribute:(NSString *)name value:(id)value;
  586. /**
  587. Sets an attribute with the given name and value to the characters in the specified range.
  588. @param name A string specifying the attribute name.
  589. @param value The attribute value associated with name. Pass `nil` or `NSNull` to
  590. remove the attribute.
  591. @param range The range of characters to which the specified attribute/value pair applies.
  592. */
  593. - (void)yy_setAttribute:(NSString *)name value:(id)value range:(NSRange)range;
  594. /**
  595. Removes all attributes in the specified range.
  596. @param range The range of characters.
  597. */
  598. - (void)yy_removeAttributesInRange:(NSRange)range;
  599. #pragma mark - Set character attribute as property
  600. ///=============================================================================
  601. /// @name Set character attribute as property
  602. ///=============================================================================
  603. /**
  604. The font of the text.
  605. @discussion Default is Helvetica (Neue) 12.
  606. @discussion Set this property applies to the entire text string.
  607. Get this property returns the first character's attribute.
  608. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  609. */
  610. @property (nonatomic, strong, readwrite) UIFont *yy_font;
  611. - (void)yy_setFont:(UIFont *)font range:(NSRange)range;
  612. /**
  613. A kerning adjustment.
  614. @discussion Default is standard kerning. The kerning attribute indicate how many
  615. points the following character should be shifted from its default offset as
  616. defined by the current character's font in points; a positive kern indicates a
  617. shift farther along and a negative kern indicates a shift closer to the current
  618. character. If this attribute is not present, standard kerning will be used.
  619. If this attribute is set to 0.0, no kerning will be done at all.
  620. @discussion Set this property applies to the entire text string.
  621. Get this property returns the first character's attribute.
  622. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  623. */
  624. @property (nonatomic, strong, readwrite) NSNumber *yy_kern;
  625. - (void)yy_setKern:(NSNumber *)kern range:(NSRange)range;
  626. /**
  627. The foreground color.
  628. @discussion Default is Black.
  629. @discussion Set this property applies to the entire text string.
  630. Get this property returns the first character's attribute.
  631. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  632. */
  633. @property (nonatomic, strong, readwrite) UIColor *yy_color;
  634. - (void)yy_setColor:(UIColor *)color range:(NSRange)range;
  635. /**
  636. The background color.
  637. @discussion Default is nil (or no background).
  638. @discussion Set this property applies to the entire text string.
  639. Get this property returns the first character's attribute.
  640. @since UIKit:6.0
  641. */
  642. @property (nonatomic, strong, readwrite) UIColor *yy_backgroundColor;
  643. - (void)yy_setBackgroundColor:(UIColor *)backgroundColor range:(NSRange)range;
  644. /**
  645. The stroke width.
  646. @discussion Default value is 0.0 (no stroke). This attribute, interpreted as
  647. a percentage of font point size, controls the text drawing mode: positive
  648. values effect drawing with stroke only; negative values are for stroke and fill.
  649. A typical value for outlined text is 3.0.
  650. @discussion Set this property applies to the entire text string.
  651. Get this property returns the first character's attribute.
  652. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  653. */
  654. @property (nonatomic, strong, readwrite) NSNumber *yy_strokeWidth;
  655. - (void)yy_setStrokeWidth:(NSNumber *)strokeWidth range:(NSRange)range;
  656. /**
  657. The stroke color.
  658. @discussion Default value is nil (same as foreground color).
  659. @discussion Set this property applies to the entire text string.
  660. Get this property returns the first character's attribute.
  661. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  662. */
  663. @property (nonatomic, strong, readwrite) UIColor *yy_strokeColor;
  664. - (void)yy_setStrokeColor:(UIColor *)strokeColor range:(NSRange)range;
  665. /**
  666. The text shadow.
  667. @discussion Default value is nil (no shadow).
  668. @discussion Set this property applies to the entire text string.
  669. Get this property returns the first character's attribute.
  670. @since UIKit:6.0 YYText:6.0
  671. */
  672. @property (nonatomic, strong, readwrite) NSShadow *yy_shadow;
  673. - (void)yy_setShadow:(NSShadow *)shadow range:(NSRange)range;
  674. /**
  675. The strikethrough style.
  676. @discussion Default value is NSUnderlineStyleNone (no strikethrough).
  677. @discussion Set this property applies to the entire text string.
  678. Get this property returns the first character's attribute.
  679. @since UIKit:6.0
  680. */
  681. @property (nonatomic, assign, readwrite) NSUnderlineStyle yy_strikethroughStyle;
  682. - (void)yy_setStrikethroughStyle:(NSUnderlineStyle)strikethroughStyle range:(NSRange)range;
  683. /**
  684. The strikethrough color.
  685. @discussion Default value is nil (same as foreground color).
  686. @discussion Set this property applies to the entire text string.
  687. Get this property returns the first character's attribute.
  688. @since UIKit:7.0
  689. */
  690. @property (nonatomic, strong, readwrite) UIColor *yy_strikethroughColor;
  691. - (void)yy_setStrikethroughColor:(UIColor *)strikethroughColor range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  692. /**
  693. The underline style.
  694. @discussion Default value is NSUnderlineStyleNone (no underline).
  695. @discussion Set this property applies to the entire text string.
  696. Get this property returns the first character's attribute.
  697. @since CoreText:3.2 UIKit:6.0
  698. */
  699. @property (nonatomic, assign, readwrite) NSUnderlineStyle yy_underlineStyle;
  700. - (void)yy_setUnderlineStyle:(NSUnderlineStyle)underlineStyle range:(NSRange)range;
  701. /**
  702. The underline color.
  703. @discussion Default value is nil (same as foreground color).
  704. @discussion Set this property applies to the entire text string.
  705. Get this property returns the first character's attribute.
  706. @since CoreText:3.2 UIKit:7.0
  707. */
  708. @property (nonatomic, strong, readwrite) UIColor *yy_underlineColor;
  709. - (void)yy_setUnderlineColor:(UIColor *)underlineColor range:(NSRange)range;
  710. /**
  711. Ligature formation control.
  712. @discussion Default is int value 1. The ligature attribute determines what kinds
  713. of ligatures should be used when displaying the string. A value of 0 indicates
  714. that only ligatures essential for proper rendering of text should be used,
  715. 1 indicates that standard ligatures should be used, and 2 indicates that all
  716. available ligatures should be used. Which ligatures are standard depends on the
  717. script and possibly the font.
  718. @discussion Set this property applies to the entire text string.
  719. Get this property returns the first character's attribute.
  720. @since CoreText:3.2 UIKit:6.0 YYText:6.0
  721. */
  722. @property (nonatomic, strong, readwrite) NSNumber *yy_ligature;
  723. - (void)yy_setLigature:(NSNumber *)ligature range:(NSRange)range;
  724. /**
  725. The text effect.
  726. @discussion Default is nil (no effect). The only currently supported value
  727. is NSTextEffectLetterpressStyle.
  728. @discussion Set this property applies to the entire text string.
  729. Get this property returns the first character's attribute.
  730. @since UIKit:7.0
  731. */
  732. @property (nonatomic, strong, readwrite) NSString *yy_textEffect;
  733. - (void)yy_setTextEffect:(NSString *)textEffect range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  734. /**
  735. The skew to be applied to glyphs.
  736. @discussion Default is 0 (no skew).
  737. @discussion Set this property applies to the entire text string.
  738. Get this property returns the first character's attribute.
  739. @since UIKit:7.0
  740. */
  741. @property (nonatomic, strong, readwrite) NSNumber *yy_obliqueness;
  742. - (void)yy_setObliqueness:(NSNumber *)obliqueness range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  743. /**
  744. The log of the expansion factor to be applied to glyphs.
  745. @discussion Default is 0 (no expansion).
  746. @discussion Set this property applies to the entire text string.
  747. Get this property returns the first character's attribute.
  748. @since UIKit:7.0
  749. */
  750. @property (nonatomic, strong, readwrite) NSNumber *yy_expansion;
  751. - (void)yy_setExpansion:(NSNumber *)expansion range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  752. /**
  753. The character's offset from the baseline, in points.
  754. @discussion Default is 0.
  755. @discussion Set this property applies to the entire text string.
  756. Get this property returns the first character's attribute.
  757. @since UIKit:7.0
  758. */
  759. @property (nonatomic, strong, readwrite) NSNumber *yy_baselineOffset;
  760. - (void)yy_setBaselineOffset:(NSNumber *)baselineOffset range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  761. /**
  762. Glyph orientation control.
  763. @discussion Default is NO. A value of NO indicates that horizontal glyph forms
  764. are to be used, YES indicates that vertical glyph forms are to be used.
  765. @discussion Set this property applies to the entire text string.
  766. Get this property returns the first character's attribute.
  767. @since CoreText:4.3 YYText:6.0
  768. */
  769. @property (nonatomic, assign, readwrite) BOOL yy_verticalGlyphForm;
  770. - (void)yy_setVerticalGlyphForm:(BOOL)verticalGlyphForm range:(NSRange)range;
  771. /**
  772. Specifies text language.
  773. @discussion Value must be a NSString containing a locale identifier. Default is
  774. unset. When this attribute is set to a valid identifier, it will be used to select
  775. localized glyphs (if supported by the font) and locale-specific line breaking rules.
  776. @discussion Set this property applies to the entire text string.
  777. Get this property returns the first character's attribute.
  778. @since CoreText:7.0 YYText:7.0
  779. */
  780. @property (nonatomic, strong, readwrite) NSString *yy_language;
  781. - (void)yy_setLanguage:(NSString *)language range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  782. /**
  783. Specifies a bidirectional override or embedding.
  784. @discussion See alse NSWritingDirection and NSWritingDirectionAttributeName.
  785. @discussion Set this property applies to the entire text string.
  786. Get this property returns the first character's attribute.
  787. @since CoreText:6.0 UIKit:7.0 YYText:6.0
  788. */
  789. @property (nonatomic, strong, readwrite) NSArray *yy_writingDirection;
  790. - (void)yy_setWritingDirection:(NSArray *)writingDirection range:(NSRange)range;
  791. /**
  792. An NSParagraphStyle object which is used to specify things like
  793. line alignment, tab rulers, writing direction, etc.
  794. @discussion Default is nil ([NSParagraphStyle defaultParagraphStyle]).
  795. @discussion Set this property applies to the entire text string.
  796. Get this property returns the first character's attribute.
  797. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  798. */
  799. @property (nonatomic, strong, readwrite) NSParagraphStyle *yy_paragraphStyle;
  800. - (void)yy_setParagraphStyle:(NSParagraphStyle *)paragraphStyle range:(NSRange)range;
  801. #pragma mark - Set paragraph attribute as property
  802. ///=============================================================================
  803. /// @name Set paragraph attribute as property
  804. ///=============================================================================
  805. /**
  806. The text alignment (A wrapper for NSParagraphStyle).
  807. @discussion Natural text alignment is realized as left or right alignment
  808. depending on the line sweep direction of the first script contained in the paragraph.
  809. @discussion Default is NSTextAlignmentNatural.
  810. @discussion Set this property applies to the entire text string.
  811. Get this property returns the first character's attribute.
  812. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  813. */
  814. @property (nonatomic, assign, readwrite) NSTextAlignment yy_alignment;
  815. - (void)yy_setAlignment:(NSTextAlignment)alignment range:(NSRange)range;
  816. /**
  817. The mode that should be used to break lines (A wrapper for NSParagraphStyle).
  818. @discussion This property contains the line break mode to be used laying out the paragraph's text.
  819. @discussion Default is NSLineBreakByWordWrapping.
  820. @discussion Set this property applies to the entire text string.
  821. Get this property returns the first character's attribute.
  822. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  823. */
  824. @property (nonatomic, assign, readwrite) NSLineBreakMode yy_lineBreakMode;
  825. - (void)yy_setLineBreakMode:(NSLineBreakMode)lineBreakMode range:(NSRange)range;
  826. /**
  827. The distance in points between the bottom of one line fragment and the top of the next.
  828. (A wrapper for NSParagraphStyle)
  829. @discussion This value is always nonnegative. This value is included in the line
  830. fragment heights in the layout manager.
  831. @discussion Default is 0.
  832. @discussion Set this property applies to the entire text string.
  833. Get this property returns the first character's attribute.
  834. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  835. */
  836. @property (nonatomic, assign, readwrite) CGFloat yy_lineSpacing;
  837. - (void)yy_setLineSpacing:(CGFloat)lineSpacing range:(NSRange)range;
  838. /**
  839. The space after the end of the paragraph (A wrapper for NSParagraphStyle).
  840. @discussion This property contains the space (measured in points) added at the
  841. end of the paragraph to separate it from the following paragraph. This value must
  842. be nonnegative. The space between paragraphs is determined by adding the previous
  843. paragraph's paragraphSpacing and the current paragraph's paragraphSpacingBefore.
  844. @discussion Default is 0.
  845. @discussion Set this property applies to the entire text string.
  846. Get this property returns the first character's attribute.
  847. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  848. */
  849. @property (nonatomic, assign, readwrite) CGFloat yy_paragraphSpacing;
  850. - (void)yy_setParagraphSpacing:(CGFloat)paragraphSpacing range:(NSRange)range;
  851. /**
  852. The distance between the paragraph's top and the beginning of its text content.
  853. (A wrapper for NSParagraphStyle).
  854. @discussion This property contains the space (measured in points) between the
  855. paragraph's top and the beginning of its text content.
  856. @discussion Default is 0.
  857. @discussion Set this property applies to the entire text string.
  858. Get this property returns the first character's attribute.
  859. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  860. */
  861. @property (nonatomic, assign, readwrite) CGFloat yy_paragraphSpacingBefore;
  862. - (void)yy_setParagraphSpacingBefore:(CGFloat)paragraphSpacingBefore range:(NSRange)range;
  863. /**
  864. The indentation of the first line (A wrapper for NSParagraphStyle).
  865. @discussion This property contains the distance (in points) from the leading margin
  866. of a text container to the beginning of the paragraph's first line. This value
  867. is always nonnegative.
  868. @discussion Default is 0.
  869. @discussion Set this property applies to the entire text string.
  870. Get this property returns the first character's attribute.
  871. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  872. */
  873. @property (nonatomic, assign, readwrite) CGFloat yy_firstLineHeadIndent;
  874. - (void)yy_setFirstLineHeadIndent:(CGFloat)firstLineHeadIndent range:(NSRange)range;
  875. /**
  876. The indentation of the receiver's lines other than the first. (A wrapper for NSParagraphStyle).
  877. @discussion This property contains the distance (in points) from the leading margin
  878. of a text container to the beginning of lines other than the first. This value is
  879. always nonnegative.
  880. @discussion Default is 0.
  881. @discussion Set this property applies to the entire text string.
  882. Get this property returns the first character's attribute.
  883. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  884. */
  885. @property (nonatomic, assign, readwrite) CGFloat yy_headIndent;
  886. - (void)yy_setHeadIndent:(CGFloat)headIndent range:(NSRange)range;
  887. /**
  888. The trailing indentation (A wrapper for NSParagraphStyle).
  889. @discussion If positive, this value is the distance from the leading margin
  890. (for example, the left margin in left-to-right text). If 0 or negative, it's the
  891. distance from the trailing margin.
  892. @discussion Default is 0.
  893. @discussion Set this property applies to the entire text string.
  894. Get this property returns the first character's attribute.
  895. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  896. */
  897. @property (nonatomic, assign, readwrite) CGFloat yy_tailIndent;
  898. - (void)yy_setTailIndent:(CGFloat)tailIndent range:(NSRange)range;
  899. /**
  900. The receiver's minimum height (A wrapper for NSParagraphStyle).
  901. @discussion This property contains the minimum height in points that any line in
  902. the receiver will occupy, regardless of the font size or size of any attached graphic.
  903. This value must be nonnegative.
  904. @discussion Default is 0.
  905. @discussion Set this property applies to the entire text string.
  906. Get this property returns the first character's attribute.
  907. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  908. */
  909. @property (nonatomic, assign, readwrite) CGFloat yy_minimumLineHeight;
  910. - (void)yy_setMinimumLineHeight:(CGFloat)minimumLineHeight range:(NSRange)range;
  911. /**
  912. The receiver's maximum line height (A wrapper for NSParagraphStyle).
  913. @discussion This property contains the maximum height in points that any line in
  914. the receiver will occupy, regardless of the font size or size of any attached graphic.
  915. This value is always nonnegative. Glyphs and graphics exceeding this height will
  916. overlap neighboring lines; however, a maximum height of 0 implies no line height limit.
  917. Although this limit applies to the line itself, line spacing adds extra space between adjacent lines.
  918. @discussion Default is 0 (no limit).
  919. @discussion Set this property applies to the entire text string.
  920. Get this property returns the first character's attribute.
  921. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  922. */
  923. @property (nonatomic, assign, readwrite) CGFloat yy_maximumLineHeight;
  924. - (void)yy_setMaximumLineHeight:(CGFloat)maximumLineHeight range:(NSRange)range;
  925. /**
  926. The line height multiple (A wrapper for NSParagraphStyle).
  927. @discussion This property contains the line break mode to be used laying out the paragraph's text.
  928. @discussion Default is 0 (no multiple).
  929. @discussion Set this property applies to the entire text string.
  930. Get this property returns the first character's attribute.
  931. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  932. */
  933. @property (nonatomic, assign, readwrite) CGFloat yy_lineHeightMultiple;
  934. - (void)yy_setLineHeightMultiple:(CGFloat)lineHeightMultiple range:(NSRange)range;
  935. /**
  936. The base writing direction (A wrapper for NSParagraphStyle).
  937. @discussion If you specify NSWritingDirectionNaturalDirection, the receiver resolves
  938. the writing direction to either NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
  939. depending on the direction for the user's `language` preference setting.
  940. @discussion Default is NSWritingDirectionNatural.
  941. @discussion Set this property applies to the entire text string.
  942. Get this property returns the first character's attribute.
  943. @since CoreText:6.0 UIKit:6.0 YYText:6.0
  944. */
  945. @property (nonatomic, assign, readwrite) NSWritingDirection yy_baseWritingDirection;
  946. - (void)yy_setBaseWritingDirection:(NSWritingDirection)baseWritingDirection range:(NSRange)range;
  947. /**
  948. The paragraph's threshold for hyphenation. (A wrapper for NSParagraphStyle).
  949. @discussion Valid values lie between 0.0 and 1.0 inclusive. Hyphenation is attempted
  950. when the ratio of the text width (as broken without hyphenation) to the width of the
  951. line fragment is less than the hyphenation factor. When the paragraph's hyphenation
  952. factor is 0.0, the layout manager's hyphenation factor is used instead. When both
  953. are 0.0, hyphenation is disabled.
  954. @discussion Default is 0.
  955. @discussion Set this property applies to the entire text string.
  956. Get this property returns the first character's attribute.
  957. @since UIKit:6.0
  958. */
  959. @property (nonatomic, assign, readwrite) float yy_hyphenationFactor;
  960. - (void)yy_setHyphenationFactor:(float)hyphenationFactor range:(NSRange)range;
  961. /**
  962. The document-wide default tab interval (A wrapper for NSParagraphStyle).
  963. @discussion This property represents the default tab interval in points. Tabs after the
  964. last specified in tabStops are placed at integer multiples of this distance (if positive).
  965. @discussion Default is 0.
  966. @discussion Set this property applies to the entire text string.
  967. Get this property returns the first character's attribute.
  968. @since CoreText:7.0 UIKit:7.0 YYText:7.0
  969. */
  970. @property (nonatomic, assign, readwrite) CGFloat yy_defaultTabInterval;
  971. - (void)yy_setDefaultTabInterval:(CGFloat)defaultTabInterval range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  972. /**
  973. An array of NSTextTab objects representing the receiver's tab stops.
  974. (A wrapper for NSParagraphStyle).
  975. @discussion The NSTextTab objects, sorted by location, define the tab stops for
  976. the paragraph style.
  977. @discussion Default is 12 TabStops with 28.0 tab interval.
  978. @discussion Set this property applies to the entire text string.
  979. Get this property returns the first character's attribute.
  980. @since CoreText:7.0 UIKit:7.0 YYText:7.0
  981. */
  982. @property (nonatomic, copy, readwrite) NSArray *yy_tabStops;
  983. - (void)yy_setTabStops:(NSArray *)tabStops range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  984. #pragma mark - Set YYText attribute as property
  985. ///=============================================================================
  986. /// @name Set YYText attribute as property
  987. ///=============================================================================
  988. /**
  989. The text shadow.
  990. @discussion Default value is nil (no shadow).
  991. @discussion Set this property applies to the entire text string.
  992. Get this property returns the first character's attribute.
  993. @since YYText:6.0
  994. */
  995. @property (nonatomic, strong, readwrite) YYTextShadow *yy_textShadow;
  996. - (void)yy_setTextShadow:(YYTextShadow *)textShadow range:(NSRange)range;
  997. /**
  998. The text inner shadow.
  999. @discussion Default value is nil (no shadow).
  1000. @discussion Set this property applies to the entire text string.
  1001. Get this property returns the first character's attribute.
  1002. @since YYText:6.0
  1003. */
  1004. @property (nonatomic, strong, readwrite) YYTextShadow *yy_textInnerShadow;
  1005. - (void)yy_setTextInnerShadow:(YYTextShadow *)textInnerShadow range:(NSRange)range;
  1006. /**
  1007. The text underline.
  1008. @discussion Default value is nil (no underline).
  1009. @discussion Set this property applies to the entire text string.
  1010. Get this property returns the first character's attribute.
  1011. @since YYText:6.0
  1012. */
  1013. @property (nonatomic, strong, readwrite) YYTextDecoration *yy_textUnderline;
  1014. - (void)yy_setTextUnderline:(YYTextDecoration *)textUnderline range:(NSRange)range;
  1015. /**
  1016. The text strikethrough.
  1017. @discussion Default value is nil (no strikethrough).
  1018. @discussion Set this property applies to the entire text string.
  1019. Get this property returns the first character's attribute.
  1020. @since YYText:6.0
  1021. */
  1022. @property (nonatomic, strong, readwrite) YYTextDecoration *yy_textStrikethrough;
  1023. - (void)yy_setTextStrikethrough:(YYTextDecoration *)textStrikethrough range:(NSRange)range;
  1024. /**
  1025. The text border.
  1026. @discussion Default value is nil (no border).
  1027. @discussion Set this property applies to the entire text string.
  1028. Get this property returns the first character's attribute.
  1029. @since YYText:6.0
  1030. */
  1031. @property (nonatomic, strong, readwrite) YYTextBorder *yy_textBorder;
  1032. - (void)yy_setTextBorder:(YYTextBorder *)textBorder range:(NSRange)range;
  1033. /**
  1034. The text background border.
  1035. @discussion Default value is nil (no background border).
  1036. @discussion Set this property applies to the entire text string.
  1037. Get this property returns the first character's attribute.
  1038. @since YYText:6.0
  1039. */
  1040. @property (nonatomic, strong, readwrite) YYTextBorder *yy_textBackgroundBorder;
  1041. - (void)yy_setTextBackgroundBorder:(YYTextBorder *)textBackgroundBorder range:(NSRange)range;
  1042. /**
  1043. The glyph transform.
  1044. @discussion Default value is CGAffineTransformIdentity (no transform).
  1045. @discussion Set this property applies to the entire text string.
  1046. Get this property returns the first character's attribute.
  1047. @since YYText:6.0
  1048. */
  1049. @property (nonatomic, assign, readwrite) CGAffineTransform yy_textGlyphTransform;
  1050. - (void)yy_setTextGlyphTransform:(CGAffineTransform)textGlyphTransform range:(NSRange)range;
  1051. #pragma mark - Set discontinuous attribute for range
  1052. ///=============================================================================
  1053. /// @name Set discontinuous attribute for range
  1054. ///=============================================================================
  1055. - (void)yy_setSuperscript:(NSNumber *)superscript range:(NSRange)range;
  1056. - (void)yy_setGlyphInfo:(CTGlyphInfoRef)glyphInfo range:(NSRange)range;
  1057. - (void)yy_setCharacterShape:(NSNumber *)characterShape range:(NSRange)range;
  1058. - (void)yy_setRunDelegate:(CTRunDelegateRef)runDelegate range:(NSRange)range;
  1059. - (void)yy_setBaselineClass:(CFStringRef)baselineClass range:(NSRange)range;
  1060. - (void)yy_setBaselineInfo:(CFDictionaryRef)baselineInfo range:(NSRange)range;
  1061. - (void)yy_setBaselineReferenceInfo:(CFDictionaryRef)referenceInfo range:(NSRange)range;
  1062. - (void)yy_setRubyAnnotation:(CTRubyAnnotationRef)ruby range:(NSRange)range NS_AVAILABLE_IOS(8_0);
  1063. - (void)yy_setAttachment:(NSTextAttachment *)attachment range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  1064. - (void)yy_setLink:(id)link range:(NSRange)range NS_AVAILABLE_IOS(7_0);
  1065. - (void)yy_setTextBackedString:(YYTextBackedString *)textBackedString range:(NSRange)range;
  1066. - (void)yy_setTextBinding:(YYTextBinding *)textBinding range:(NSRange)range;
  1067. - (void)yy_setTextAttachment:(YYTextAttachment *)textAttachment range:(NSRange)range;
  1068. - (void)yy_setTextHighlight:(YYTextHighlight *)textHighlight range:(NSRange)range;
  1069. - (void)yy_setTextBlockBorder:(YYTextBorder *)textBlockBorder range:(NSRange)range;
  1070. - (void)yy_setTextRubyAnnotation:(YYTextRubyAnnotation *)ruby range:(NSRange)range NS_AVAILABLE_IOS(8_0);
  1071. #pragma mark - Convenience methods for text highlight
  1072. ///=============================================================================
  1073. /// @name Convenience methods for text highlight
  1074. ///=============================================================================
  1075. /**
  1076. Convenience method to set text highlight
  1077. @param range text range
  1078. @param color text color (pass nil to ignore)
  1079. @param backgroundColor text background color when highlight
  1080. @param userInfo user information dictionary (pass nil to ignore)
  1081. @param tapAction tap action when user tap the highlight (pass nil to ignore)
  1082. @param longPressAction long press action when user long press the highlight (pass nil to ignore)
  1083. */
  1084. - (void)yy_setTextHighlightRange:(NSRange)range
  1085. color:(UIColor *)color
  1086. backgroundColor:(UIColor *)backgroundColor
  1087. userInfo:(NSDictionary *)userInfo
  1088. tapAction:(YYTextAction)tapAction
  1089. longPressAction:(YYTextAction)longPressAction;
  1090. /**
  1091. Convenience method to set text highlight
  1092. @param range text range
  1093. @param color text color (pass nil to ignore)
  1094. @param backgroundColor text background color when highlight
  1095. @param tapAction tap action when user tap the highlight (pass nil to ignore)
  1096. */
  1097. - (void)yy_setTextHighlightRange:(NSRange)range
  1098. color:(UIColor *)color
  1099. backgroundColor:(UIColor *)backgroundColor
  1100. tapAction:(YYTextAction)tapAction;
  1101. /**
  1102. Convenience method to set text highlight
  1103. @param range text range
  1104. @param color text color (pass nil to ignore)
  1105. @param backgroundColor text background color when highlight
  1106. @param userInfo tap action when user tap the highlight (pass nil to ignore)
  1107. */
  1108. - (void)yy_setTextHighlightRange:(NSRange)range
  1109. color:(UIColor *)color
  1110. backgroundColor:(UIColor *)backgroundColor
  1111. userInfo:(NSDictionary *)userInfo;
  1112. #pragma mark - Utilities
  1113. ///=============================================================================
  1114. /// @name Utilities
  1115. ///=============================================================================
  1116. /**
  1117. Inserts into the receiver the characters of a given string at a given location.
  1118. The new string inherit the attributes of the first replaced character from location.
  1119. @param string The string to insert into the receiver, must not be nil.
  1120. @param location The location at which string is inserted. The location must not
  1121. exceed the bounds of the receiver.
  1122. @throw Raises an NSRangeException if the location out of bounds.
  1123. */
  1124. - (void)yy_insertString:(NSString *)string atIndex:(NSUInteger)location;
  1125. /**
  1126. Adds to the end of the receiver the characters of a given string.
  1127. The new string inherit the attributes of the receiver's tail.
  1128. @param string The string to append to the receiver, must not be nil.
  1129. */
  1130. - (void)yy_appendString:(NSString *)string;
  1131. /**
  1132. Set foreground color with [UIColor clearColor] in joined-emoji range.
  1133. Emoji drawing will not be affected by the foreground color.
  1134. @discussion In iOS 8.3, Apple releases some new diversified emojis.
  1135. There's some single emoji which can be assembled to a new 'joined-emoji'.
  1136. The joiner is unicode character 'ZERO WIDTH JOINER' (U+200D).
  1137. For example: 👨👩👧👧 -> 👨‍👩‍👧‍👧.
  1138. When there are more than 5 'joined-emoji' in a same CTLine, CoreText may render some
  1139. extra glyphs above the emoji. It's a bug in CoreText, try this method to avoid.
  1140. This bug is fixed in iOS 9.
  1141. */
  1142. - (void)yy_setClearColorToJoinedEmoji;
  1143. /**
  1144. Removes all discontinuous attributes in a specified range.
  1145. See `allDiscontinuousAttributeKeys`.
  1146. @param range A text range.
  1147. */
  1148. - (void)yy_removeDiscontinuousAttributesInRange:(NSRange)range;
  1149. /**
  1150. Returns all discontinuous attribute keys, such as RunDelegate/Attachment/Ruby.
  1151. @discussion These attributes can only set to a specified range of text, and
  1152. should not extend to other range when editing text.
  1153. */
  1154. + (NSArray *)yy_allDiscontinuousAttributeKeys;
  1155. @end