功能強大的 iOS 富文本編輯與顯示框架:YYText

jopen 9年前發布 | 202K 次閱讀 YYText iOS開發 移動開發

功能強大的 iOS 富文本編輯與顯示框架。
(該項目是 YYKit 組件之一)

特性

  • API 兼容 UILabel 和 UITextView
  • 支持高性能的異步排版和渲染
  • 擴展了 CoreText 的屬性以支持更多文字效果
  • 支持 UIImage、UIView、CALayer 作為圖文混排元素
  • 支持添加自定義樣式的、可點擊的文本高亮范圍
  • 支持自定義文本解析 (內置簡單的 Markdown/表情解析)
  • 支持文本容器路徑、內部留空路徑的控制
  • 支持文字豎排版,可用于編輯和顯示中日韓文本
  • 支持圖片和富文本的復制粘貼
  • 文本編輯時,支持富文本占位符
  • 支持自定義鍵盤視圖
  • 撤銷和重做次數的控制
  • 富文本的序列化與反序列化支持
  • 支持多語言,支持 VoiceOver
  • 全部代碼都有文檔注釋

架構

YYText 和 TextKit 架構對比

文本屬性

YYText 原生支持的屬性

Demo Attribute Name Class
TextBackedString YYTextBackedString
TextBinding YYTextBinding
TextShadow YYTextShadow
TextInnerShadow YYTextShadow
TextUnderline YYTextDecoration
TextStrickthrough YYTextDecoration
TextBorder YYTextBorder
TextBackgroundBorder YYTextBorder
TextBlockBorder YYTextBorder
TextAttachment YYTextAttachment
TextHighlight YYTextHighlight
TextGlyphTransform NSValue(CGAffineTransform)

YYText 支持的 CoreText 屬性

Demo Attribute Name Class
Font UIFont(CTFontRef)
Kern NSNumber
StrokeWidth NSNumber
StrokeColor CGColorRef
Shadow NSShadow
Ligature NSNumber
VerticalGlyphForm NSNumber(BOOL)
WritingDirection NSArray(NSNumber)
RunDelegate CTRunDelegateRef
TextAlignment NSParagraphStyle
(NSTextAlignment)
LineBreakMode NSParagraphStyle
(NSLineBreakMode)
LineSpacing NSParagraphStyle
(CGFloat)
ParagraphSpacing
ParagraphSpacingBefore
NSParagraphStyle
(CGFloat)
FirstLineHeadIndent NSParagraphStyle
(CGFloat)
HeadIndent NSParagraphStyle
(CGFloat)
TailIndent NSParagraphStyle
(CGFloat)
MinimumLineHeight NSParagraphStyle
(CGFloat)
MaximumLineHeight NSParagraphStyle
(CGFloat)
LineHeightMultiple NSParagraphStyle
(CGFloat)
BaseWritingDirection NSParagraphStyle
(NSWritingDirection)
DefaultTabInterval
TabStops
NSParagraphStyle
CGFloat/NSArray(NSTextTab)

用法

基本用法

// YYLabel (和 UILabel 用法一致)
YYLabel *label = [YYLabel new];
label.frame = ...
label.font = ...
label.textColor = ...
label.textAlignment = ...
label.lineBreakMode = ...
label.numberOfLines = ...
label.text = ...

// YYTextView (和 UITextView 用法一致)
YYTextView *textView = [YYTextView new];
textView.frame = ...
textView.font = ...
textView.textColor = ...
textView.dataDetectorTypes = ...
textView.placeHolderText = ...
textView.placeHolderTextColor = ...
textView.delegate = ...

項目主頁:http://www.baiduhome.net/lib/view/home/1447216582147

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!