ZSSRichTextEditor.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // ZSSRichTextEditorViewController.h
  3. // ZSSRichTextEditor
  4. //
  5. // Created by Nicholas Hubbard on 11/30/13.
  6. // Copyright (c) 2013 Zed Said Studio. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "HRColorPickerViewController.h"
  10. #import "ZSSFontsViewController.h"
  11. /**
  12. * The types of toolbar items that can be added
  13. */
  14. static NSString * const ZSSRichTextEditorToolbarBold = @"com.zedsaid.toolbaritem.bold";
  15. static NSString * const ZSSRichTextEditorToolbarItalic = @"com.zedsaid.toolbaritem.italic";
  16. static NSString * const ZSSRichTextEditorToolbarSubscript = @"com.zedsaid.toolbaritem.subscript";
  17. static NSString * const ZSSRichTextEditorToolbarSuperscript = @"com.zedsaid.toolbaritem.superscript";
  18. static NSString * const ZSSRichTextEditorToolbarStrikeThrough = @"com.zedsaid.toolbaritem.strikeThrough";
  19. static NSString * const ZSSRichTextEditorToolbarUnderline = @"com.zedsaid.toolbaritem.underline";
  20. static NSString * const ZSSRichTextEditorToolbarRemoveFormat = @"com.zedsaid.toolbaritem.removeFormat";
  21. static NSString * const ZSSRichTextEditorToolbarJustifyLeft = @"com.zedsaid.toolbaritem.justifyLeft";
  22. static NSString * const ZSSRichTextEditorToolbarJustifyCenter = @"com.zedsaid.toolbaritem.justifyCenter";
  23. static NSString * const ZSSRichTextEditorToolbarJustifyRight = @"com.zedsaid.toolbaritem.justifyRight";
  24. static NSString * const ZSSRichTextEditorToolbarJustifyFull = @"com.zedsaid.toolbaritem.justifyFull";
  25. static NSString * const ZSSRichTextEditorToolbarH1 = @"com.zedsaid.toolbaritem.h1";
  26. static NSString * const ZSSRichTextEditorToolbarH2 = @"com.zedsaid.toolbaritem.h2";
  27. static NSString * const ZSSRichTextEditorToolbarH3 = @"com.zedsaid.toolbaritem.h3";
  28. static NSString * const ZSSRichTextEditorToolbarH4 = @"com.zedsaid.toolbaritem.h4";
  29. static NSString * const ZSSRichTextEditorToolbarH5 = @"com.zedsaid.toolbaritem.h5";
  30. static NSString * const ZSSRichTextEditorToolbarH6 = @"com.zedsaid.toolbaritem.h6";
  31. static NSString * const ZSSRichTextEditorToolbarTextColor = @"com.zedsaid.toolbaritem.textColor";
  32. static NSString * const ZSSRichTextEditorToolbarBackgroundColor = @"com.zedsaid.toolbaritem.backgroundColor";
  33. static NSString * const ZSSRichTextEditorToolbarUnorderedList = @"com.zedsaid.toolbaritem.unorderedList";
  34. static NSString * const ZSSRichTextEditorToolbarOrderedList = @"com.zedsaid.toolbaritem.orderedList";
  35. static NSString * const ZSSRichTextEditorToolbarHorizontalRule = @"com.zedsaid.toolbaritem.horizontalRule";
  36. static NSString * const ZSSRichTextEditorToolbarIndent = @"com.zedsaid.toolbaritem.indent";
  37. static NSString * const ZSSRichTextEditorToolbarOutdent = @"com.zedsaid.toolbaritem.outdent";
  38. static NSString * const ZSSRichTextEditorToolbarInsertImage = @"com.zedsaid.toolbaritem.insertImage";
  39. static NSString * const ZSSRichTextEditorToolbarInsertImageFromDevice = @"com.zedsaid.toolbaritem.insertImageFromDevice";
  40. static NSString * const ZSSRichTextEditorToolbarInsertLink = @"com.zedsaid.toolbaritem.insertLink";
  41. static NSString * const ZSSRichTextEditorToolbarRemoveLink = @"com.zedsaid.toolbaritem.removeLink";
  42. static NSString * const ZSSRichTextEditorToolbarQuickLink = @"com.zedsaid.toolbaritem.quickLink";
  43. static NSString * const ZSSRichTextEditorToolbarUndo = @"com.zedsaid.toolbaritem.undo";
  44. static NSString * const ZSSRichTextEditorToolbarRedo = @"com.zedsaid.toolbaritem.redo";
  45. static NSString * const ZSSRichTextEditorToolbarViewSource = @"com.zedsaid.toolbaritem.viewSource";
  46. static NSString * const ZSSRichTextEditorToolbarParagraph = @"com.zedsaid.toolbaritem.paragraph";
  47. static NSString * const ZSSRichTextEditorToolbarAll = @"com.zedsaid.toolbaritem.all";
  48. static NSString * const ZSSRichTextEditorToolbarNone = @"com.zedsaid.toolbaritem.none";
  49. static NSString * const ZSSRichTextEditorToolbarFonts = @"com.zedsaid.toolbaritem.fonts";
  50. @class ZSSBarButtonItem;
  51. /**
  52. * The viewController used with ZSSRichTextEditor
  53. */
  54. @interface ZSSRichTextEditor : UIViewController <UIWebViewDelegate, HRColorPickerViewControllerDelegate, UITextViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate,ZSSFontsViewControllerDelegate>
  55. /**
  56. * The base URL to use for the webView
  57. */
  58. @property (nonatomic, strong) NSURL *baseURL;
  59. /**
  60. * If the HTML should be formatted to be pretty
  61. */
  62. @property (nonatomic) BOOL formatHTML;
  63. /**
  64. * If the keyboard should be shown when the editor loads
  65. */
  66. @property (nonatomic) BOOL shouldShowKeyboard;
  67. /**
  68. * If the toolbar should always be shown or not
  69. */
  70. @property (nonatomic) BOOL alwaysShowToolbar;
  71. /**
  72. * If the sub class recieves text did change events or not
  73. */
  74. @property (nonatomic) BOOL receiveEditorDidChangeEvents;
  75. /**
  76. * The placeholder text to use if there is no editor content
  77. */
  78. @property (nonatomic, strong) NSString *placeholder;
  79. /**
  80. * Toolbar items to include
  81. */
  82. @property (nonatomic, strong) NSArray *enabledToolbarItems;
  83. /**
  84. * Color to tint the toolbar items
  85. */
  86. @property (nonatomic, strong) UIColor *toolbarItemTintColor;
  87. /**
  88. * Color to tint selected items
  89. */
  90. @property (nonatomic, strong) UIColor *toolbarItemSelectedTintColor;
  91. /**
  92. * Sets the HTML for the entire editor
  93. *
  94. * @param html HTML string to set for the editor
  95. *
  96. */
  97. - (void)setHTML:(NSString *)html;
  98. /**
  99. * Returns the HTML from the Rich Text Editor
  100. *
  101. */
  102. - (NSString *)getHTML;
  103. /**
  104. * Returns the plain text from the Rich Text Editor
  105. *
  106. */
  107. - (NSString *)getText;
  108. /**
  109. * Inserts HTML at the caret position
  110. *
  111. * @param html HTML string to insert
  112. *
  113. */
  114. - (void)insertHTML:(NSString *)html;
  115. /**
  116. * Manually focuses on the text editor
  117. */
  118. - (void)focusTextEditor;
  119. /**
  120. * Manually dismisses on the text editor
  121. */
  122. - (void)blurTextEditor;
  123. /**
  124. * Shows the insert image dialog with optinal inputs
  125. *
  126. * @param url The URL for the image
  127. * @param alt The alt for the image
  128. */
  129. - (void)showInsertImageDialogWithLink:(NSString *)url alt:(NSString *)alt;
  130. /**
  131. * Inserts an image
  132. *
  133. * @param url The URL for the image
  134. * @param alt The alt attribute for the image
  135. */
  136. - (void)insertImage:(NSString *)url alt:(NSString *)alt;
  137. /**
  138. * Shows the insert link dialog with optional inputs
  139. *
  140. * @param url The URL for the link
  141. * @param title The tile for the link
  142. */
  143. - (void)showInsertLinkDialogWithLink:(NSString *)url title:(NSString *)title;
  144. /**
  145. * Inserts a link
  146. *
  147. * @param url The URL for the link
  148. * @param title The title for the link
  149. */
  150. - (void)insertLink:(NSString *)url title:(NSString *)title;
  151. /**
  152. * Gets called when the insert URL picker button is tapped in an alertView
  153. *
  154. * @warning The default implementation of this method is blank and does nothing
  155. */
  156. - (void)showInsertURLAlternatePicker;
  157. /**
  158. * Gets called when the insert Image picker button is tapped in an alertView
  159. *
  160. * @warning The default implementation of this method is blank and does nothing
  161. */
  162. - (void)showInsertImageAlternatePicker;
  163. /**
  164. * Dismisses the current AlertView
  165. */
  166. - (void)dismissAlertView;
  167. /**
  168. * Add a custom UIBarButtonItem by using a UIButton
  169. */
  170. - (void)addCustomToolbarItemWithButton:(UIButton*)button;
  171. /**
  172. * Add a custom ZSSBarButtonItem
  173. */
  174. - (void)addCustomToolbarItem:(ZSSBarButtonItem *)item;
  175. /**
  176. * Scroll event callback with position
  177. */
  178. - (void)editorDidScrollWithPosition:(NSInteger)position;
  179. /**
  180. * Text change callback with text and html
  181. */
  182. - (void)editorDidChangeWithText:(NSString *)text andHTML:(NSString *)html;
  183. /**
  184. * Hashtag callback with word
  185. */
  186. - (void)hashtagRecognizedWithWord:(NSString *)word;
  187. /**
  188. * Mention callback with word
  189. */
  190. - (void)mentionRecognizedWithWord:(NSString *)word;
  191. /**
  192. * Set custom css
  193. */
  194. - (void)setCSS:(NSString *)css;
  195. @end