Convert Figma logo to code with AI

nnhubbard logoZSSRichTextEditor

A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view

3,784
584
3,784
133

Top Related Projects

43,470

Quill is a modern WYSIWYG editor built for compatibility and extensibility

14,968

The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.

Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.

18,951

A rich text editor for everyday writing

Quick Overview

ZSSRichTextEditor is an open-source rich text WYSIWYG editor for iOS, built using HTML and JavaScript. It provides a customizable interface for text editing with various formatting options, making it suitable for applications that require advanced text input capabilities.

Pros

  • Offers a wide range of text formatting options, including bold, italic, underline, and more
  • Supports image insertion and manipulation within the editor
  • Customizable toolbar with the ability to add or remove specific formatting options
  • Provides a native iOS look and feel while leveraging web technologies

Cons

  • Last updated in 2017, which may indicate lack of recent maintenance or updates
  • May have compatibility issues with newer iOS versions or devices
  • Limited documentation and examples available in the repository
  • Potential performance issues when handling large amounts of text or complex formatting

Code Examples

  1. Initializing the editor:
let richTextEditor = ZSSRichTextEditor()
view.addSubview(richTextEditor)
  1. Customizing the toolbar:
richTextEditor.enabledToolbarItems = [
    ZSSRichTextEditorToolbarItem.bold,
    ZSSRichTextEditorToolbarItem.italic,
    ZSSRichTextEditorToolbarItem.underline
]
  1. Retrieving the edited HTML content:
let htmlContent = richTextEditor.getHTML()
  1. Inserting an image into the editor:
richTextEditor.insertImage("https://example.com/image.jpg")

Getting Started

To use ZSSRichTextEditor in your iOS project:

  1. Add the ZSSRichTextEditor folder to your Xcode project.
  2. Import the necessary files in your view controller:
import UIKit

class ViewController: UIViewController {
    var richTextEditor: ZSSRichTextEditor!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        richTextEditor = ZSSRichTextEditor()
        richTextEditor.frame = view.bounds
        view.addSubview(richTextEditor)
    }
}
  1. Customize the editor as needed using the available methods and properties.

Competitor Comparisons

43,470

Quill is a modern WYSIWYG editor built for compatibility and extensibility

Pros of Quill

  • Cross-platform compatibility (web-based)
  • Extensive customization options and API
  • Active development and community support

Cons of Quill

  • Steeper learning curve for advanced features
  • Larger file size compared to native solutions

Code Comparison

ZSSRichTextEditor (Objective-C):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.editorView = [[ZSSRichTextEditor alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.editorView];
}

Quill (JavaScript):

var quill = new Quill('#editor', {
  theme: 'snow',
  modules: {
    toolbar: [['bold', 'italic'], ['link', 'image']]
  }
});

Summary

ZSSRichTextEditor is a native iOS rich text editor, while Quill is a powerful web-based rich text editor. ZSSRichTextEditor offers seamless integration with iOS apps but is limited to the Apple ecosystem. Quill provides cross-platform compatibility and extensive customization options, making it suitable for web applications and hybrid mobile apps. However, Quill may have a steeper learning curve for advanced features and a larger file size compared to native solutions like ZSSRichTextEditor.

14,968

The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular

Pros of TinyMCE

  • More feature-rich and customizable, with a wide range of plugins and themes
  • Better cross-browser compatibility and support for modern web technologies
  • Larger community and more frequent updates

Cons of TinyMCE

  • Heavier and potentially slower, especially for simpler use cases
  • Steeper learning curve due to its extensive API and configuration options
  • May be overkill for mobile-specific applications

Code Comparison

ZSSRichTextEditor (Objective-C):

- (void)enabledEditingItems {
    [self.editorView evaluateJavaScript:@"zss_editor.enabledEditingItems();" completionHandler:nil];
}

TinyMCE (JavaScript):

tinymce.init({
  selector: 'textarea',
  plugins: 'advlist autolink lists link image charmap print preview anchor',
  toolbar: 'undo redo | formatselect | bold italic | alignleft aligncenter alignright | bullist numlist outdent indent | link image'
});

ZSSRichTextEditor is specifically designed for iOS, offering a native mobile editing experience. It's lightweight and easy to integrate into iOS projects. However, it has limited customization options and fewer features compared to TinyMCE.

TinyMCE is a versatile, web-based rich text editor that can be used across various platforms, including mobile web applications. It offers extensive customization and a wide range of features, but may require more setup and optimization for mobile-specific use cases.

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.

Pros of CKEditor 5

  • More comprehensive and feature-rich, offering a wide range of plugins and customization options
  • Active development with frequent updates and a large community support
  • Better documentation and extensive API reference

Cons of CKEditor 5

  • Larger file size and potentially heavier on resources
  • Steeper learning curve due to its extensive features and configuration options
  • May be overkill for simple text editing needs

Code Comparison

ZSSRichTextEditor (Objective-C):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.editorView = [[ZSSRichTextEditor alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.editorView];
}

CKEditor 5 (JavaScript):

import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

ClassicEditor
    .create(document.querySelector('#editor'))
    .then(editor => {
        console.log('Editor was initialized', editor);
    })
    .catch(error => {
        console.error(error);
    });

The code comparison shows that ZSSRichTextEditor is implemented in Objective-C for iOS development, while CKEditor 5 is a JavaScript-based editor for web applications. CKEditor 5 offers a more modular approach with various build options and plugins, whereas ZSSRichTextEditor provides a simpler implementation for iOS-specific rich text editing.

Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.

Pros of medium-editor

  • More active development and larger community support
  • Extensive customization options and plugins
  • Lightweight and easy to integrate into existing projects

Cons of medium-editor

  • Lacks native mobile support
  • May require additional configuration for complex formatting options
  • Less suitable for iOS-specific projects

Code Comparison

ZSSRichTextEditor (Objective-C):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.richTextEditor = [[ZSSRichTextEditor alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.richTextEditor];
}

medium-editor (JavaScript):

var editor = new MediumEditor('.editable', {
    toolbar: {
        buttons: ['bold', 'italic', 'underline', 'anchor', 'h2', 'h3', 'quote']
    },
    placeholder: {
        text: 'Type your text'
    }
});

Summary

ZSSRichTextEditor is an iOS-specific rich text editor, while medium-editor is a JavaScript-based solution for web applications. ZSSRichTextEditor offers better integration with iOS development, but medium-editor provides more flexibility and cross-platform compatibility. The choice between the two depends on the specific project requirements and target platform.

18,951

A rich text editor for everyday writing

Pros of Trix

  • Cross-platform compatibility (web-based)
  • Active development and maintenance by Basecamp
  • Extensive documentation and community support

Cons of Trix

  • Limited native mobile support
  • Steeper learning curve for customization
  • Larger file size compared to ZSSRichTextEditor

Code Comparison

ZSSRichTextEditor (Objective-C):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.editorView = [[ZSSRichTextEditor alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.editorView];
}

Trix (JavaScript):

document.addEventListener("trix-initialize", function(event) {
  var element = event.target
  var editor = element.editor
  editor.insertString("Welcome to Trix!")
})

Summary

Trix is a web-based rich text editor with cross-platform compatibility and extensive documentation. It's actively maintained by Basecamp but has limited native mobile support. ZSSRichTextEditor is an iOS-specific rich text editor with a simpler implementation for mobile apps. Trix offers more features and community support, while ZSSRichTextEditor provides a lightweight solution for iOS development. The choice between the two depends on the specific project requirements and target platforms.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ZSSRichTextEditor

The Editor

ZSSRichTextEditor is a beautiful Rich Text WYSIWYG Editor for iOS. It includes all of the standard editor tools one would expect from a WYSIWYG editor as well as an amazing source view with syntax highlighting.

toolbar

The editor is used how any other text input area in iOS is used. A selection of text or content is made, then tapping on the toolbar item below will apply that style. A Source View is also included, you can make changes and this will be reflected in the editor preview.

editor

Colors

We wanted to have a really beautiful color picker to make changing colors really simple. So, we used the open-source HRColorPicker which was exactly what we were looking for. Choosing colors for text or background is simple and seamless.

colors

How It Works

Just subclass ZSSRichTextEditor and use the following:

// HTML Content to set in the editor
NSString *html = @"<!-- This is an HTML comment -->"
"<p>This is a test of the <strong>ZSSRichTextEditor</strong> by <a title=\"Zed Said\" href=\"http://www.zedsaid.com\">Zed Said Studio</a></p>";

// Set the base URL if you would like to use relative links, such as to images.
self.baseURL = [NSURL URLWithString:@"http://www.zedsaid.com"];

// If you want to pretty print HTML within the source view.
self.formatHTML = YES;

// set the initial HTML for the editor
[self setHTML:html];

If you want to retrieve the HTML from the editor:

// Returns an NSString
[self getHTML];

Insert HTML at the current caret position:

NSString *html = @"<strong>I love cats!</strong>";
[self insertHTML:html];

Change the tint color of the toolbar buttons:

// Set the toolbar item color
self.toolbarItemTintColor = [UIColor greenColor];

// Set the toolbar selected color
self.toolbarItemSelectedTintColor = [UIColor redColor];

Show only specified buttons in the toolbar:

self.enabledToolbarItems = @[ZSSRichTextEditorToolbarBold, ZSSRichTextEditorToolbarH1, ZSSRichTextEditorToolbarParagraph];

Always show the toolbar even when the keyboard is hidden:

self.alwaysShowToolbar = YES;

Set A Placeholder

[self setPlaceholder:@"This is a placeholder that will show when there is no content(html)"];

Insert Link and Insert Image

If you want to manually insert a link or image where the cursor is, you can use the following methods:

Insert Image

- (void)insertImage:(NSString *)url alt:(NSString *)alt;

Insert Link

- (void)insertLink:(NSString *)url title:(NSString *)title;

Custom Pickers

You can implement your own pickers for images and links if you have an alternate method that you are wanting to use. E.g., uploading an image from your camera roll then inserting the URL.

When the alternate picker icon (crosshair) is tapped it will call the corresponding method, which you need to override in your ZSSRichTextEditor subclass (see example project):

- (void)showInsertURLAlternatePicker {
    
    [self dismissAlertView];
    
    // Show your custom picker
    
}


- (void)showInsertImageAlternatePicker {
    
    [self dismissAlertView];
    
    // Show your custom picker
    
}

Custom Toolbar Buttons

UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, buttonWidth, 28.0f)];
[myButton setTitle:@"My Button" forState:UIControlStateNormal];
[myButton addTarget:self
             action:@selector(didTapCustomToolbarButton:)
   forControlEvents:UIControlEventTouchUpInside];

[self addCustomToolbarItemWithButton:myButton];

Custom CSS

NSString *customCSS = @"a {text-decoration:none;} a:hover {color:#FF0000;}";
[self setCSS:customCSS];

Receive Editor Did Change Events

Add the following to your viewDidLoad method:

self.receiveEditorDidChangeEvents = YES;

Then you will receive events in the following method:

- (void)editorDidChangeWithText:(NSString *)text andHTML:(NSString *)html {
    
    NSLog(@"Text Has Changed: %@", text);
    
    NSLog(@"HTML Has Changed: %@", html);
    
}

Receive Hashtag & Mention Events

Hashtags:

- (void)hashtagRecognizedWithWord:(NSString *)word {
    
    NSLog(@"Hashtag has been recognized: %@", word);
    
}

Mentions:

- (void)mentionRecognizedWithWord:(NSString *)word {
    
    NSLog(@"Mention has been recognized: %@", word);
    
}

Supported Functions

ZSSRichTextEditor has the following functions:

  • Bold
  • Italic
  • Subscript
  • Superscript
  • Strikethrough
  • Underline
  • Remove Formatting
  • Font
  • Justify Left
  • Justify Center
  • Justify Right
  • Justify Full
  • Paragraph
  • Heading 1
  • Heading 2
  • Heading 3
  • Heading 4
  • Heading 5
  • Heading 6
  • Undo
  • Redo
  • Unordered List
  • Ordered List
  • Indent
  • Outdent
  • Insert Image
  • Insert Link
  • Quick Link
  • Unlink
  • Horizontal Rule
  • View Source
  • Text Color
  • Background Color

Installation

You can use CocoaPods or manually using the following instructions:

ZSSRichTextEditor requires iOS7 as well as CoreGraphics.framework and CoreText.framework.

  • Copy the Source folder to your project.
  • Subclass ZSSRichTextEditor and implement the methods as mentioned above.

When using ZSSRichTextEditor in your own project, XCode will automatically add ZSSRichTextEditor.js to compile sources under build phases, this will cause ZSSRichTextEditor to not work correctly as the javascript file won't be included in your app. Instead, remove it from compile sources and add it to copy bundle resources.

Attribution

ZSSRichTextEditor uses portions of code from the following sources:

ComponentDescriptionLicense
CYRTextViewCYRTextView is a UITextView subclass that implements a variety of features that are relevant to a syntax or code text view.MIT
HRColorPickerSimple color picker for iPhoneBSD
jQueryjQuery is a fast, small, and feature-rich JavaScript library.MIT
JS BeautifierMakes ugly Javascript prettyMIT

Contact

Visit us online at http://www.zedsaid.com or @zedsaid.