ZSSRichTextEditor.h 6.5 KB

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