Skip to content

hstdt/iOS-Rich-Text-Editor

 
 

Repository files navigation

RichTextEditor-iOS Version

0.9 TODO

  • Drop WEPopover dependency and use native popovers on iPhone (see here and here). -- Dropped dependency but decided not to use popovers on iPhone per interface guidelines.
  • Change style to have starting brackets on the same line as if statements & function calls (etc.) -- This is now done in RichTextEditor.m but not other files
  • Bug fixing/checking
  • Fix NSUndoManager undo/redo when using bulleted lists
  • Make the toolbar more pretty
  • Framework output
  • New screenshots for this readme
  • Make use of iOS NSTextStorage
  • Port fixes and changes from OS X (see here)
  • Convert this README file to use ## instead of ----- for h1/2/3/4/5 syntax
  • Cocoapods
  • Carthage

1.0 TODO

  • Support numbered lists

Breaking Change Warning!

The BULLET_STRING was modified from '\u2022\t' to '\u2022\u00a0'. You may need to update your own code or saved rich text files accordingly.

RichTextEditor for iPhone & iPad

Requirements: iOS 8.0 or higher

Features:

  • Bold
  • Italic
  • Underline
  • StrikeThrough
  • Bulleted lists
  • Font
  • Font size
  • Text background color
  • Text foregroud color
  • Text alignment
  • Paragraph Indent/Outdent

Installing

Make sure to link the MobileCoreServices framework.

Delegate Warning!

In order to intercept delegate messages, this class uses WZProtocolInterceptor. If you call self.richTextView.delegate, you will get the WZProtocolInterceptor object, not the original delegate that you set earlier with self.richTextView.delegate = ...! If you need to get the delegate that you set, call [self.richTextView textViewDelegate]. (This is caused by the richTextView needing its own delegate methods.)

Note

If text is set before the view is fully shown, the text may start scrolled to the bottom. Look here for solutions.

Custom Font Size Selection

Font size selection can be customized by implementing the following data source method

- (NSArray *)fontSizeSelectionForRichTextEditor:(RichTextEditor *)richTextEditor
{
	// pass an array of NSNumbers
	return @[@5, @10, @20, @30];
}

Custom Font Family Selection

Font family selection can be customized by implementing the following data source method

- (NSArray *)fontFamilySelectionForRichTextEditor:(RichTextEditor *)richTextEditor {
    // pass an array of Strings
    // Can be taken from [UIFont familyNames]
    return @[@"Helvetica", @"Arial", @"Marion", @"Papyrus"];
}

Presentation Style

You can switch between popover, or modal (presenting font-picker, font-size-picker, color-picker dialogs) by implementing the following data source method

- (RichTextEditorToolbarPresentationStyle)presentarionStyleForRichTextEditor:(RichTextEditor *)richTextEditor
{
  // RichTextEditorToolbarPresentationStyleModal Or RichTextEditorToolbarPresentationStylePopover
	return RichTextEditorToolbarPresentationStyleModal;
}

Modal Presentation Style

When presentarionStyleForRichTextEditor is a modal, modal-transition-style & modal-presentation-style can be configured

- (UIModalPresentationStyle)modalPresentationStyleForRichTextEditor:(RichTextEditor *)richTextEditor {
	return UIModalPresentationFormSheet;
}

- (UIModalTransitionStyle)modalTransitionStyleForRichTextEditor:(RichTextEditor *)richTextEditor {
	return UIModalTransitionStyleFlipHorizontal;
}

Customizing Features

Features can be turned on/off by iplementing the following data source method

- (RichTextEditorFeature)featuresEnabledForRichTextEditor:(RichTextEditor *)richTextEditor {
   return RichTextEditorFeatureFont | 
          RichTextEditorFeatureFontSize |
          RichTextEditorFeatureBold |
          RichTextEditorFeatureParagraphIndentation;
}

Enable/Disable RichText Toolbar

You can hide the rich text toolbar by implementing the following method. This method gets called everytime textView becomes first responder. This can be usefull when you don't want the toolbar, instead you want to use the basic features (bold, italic, underline, strikeThrough), thoguht the UIMeMenuController

- (BOOL)shouldDisplayToolbarForRichTextEditor:(RichTextEditor *)richTextEditor {
   return YES;
} 

Enable/Disable UIMenuController Options

On default the UIMenuController options (bold, italic, underline, strikeThrough) are turned off. You can implement the following method if you want these features to be available through the UIMenuController along with copy/paste/selectAll etc.

- (BOOL)shouldDisplayRichTextOptionsInMenuControllerForRichTextrEditor:(RichTextEditor *)richTextEdiotor {
   return YES;
} 

Credits

Original Rich Text Editor code by aryaxt at iOS Rich Text Editor.

About

A Rich Text Editor library for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 99.6%
  • Ruby 0.4%