RichEditorView
RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing.
Top Related Projects
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
Integrate iCloud into iOS document projects with one-line code methods. Sync, upload, manage, and remove documents from iCloud quickly and easily. Helps to make iCloud "just work" for developers too.
Fully open source text editor for iOS written in SwiftUI.
📝 The next in the generations of 'growing textviews' optimized for iOS 8 and above.
⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features
Quick Overview
RichEditorView is an iOS library that provides a rich text editor component for iOS applications. It allows users to create and edit formatted text with various styling options, such as bold, italic, underline, and more. The library is built using Swift and offers a customizable interface for integrating rich text editing capabilities into iOS apps.
Pros
- Easy integration with existing iOS projects
- Supports a wide range of text formatting options
- Customizable toolbar and appearance
- Written in Swift, providing better performance and type safety
Cons
- Limited documentation and examples
- May require additional work to implement advanced features
- Not actively maintained (last update was several years ago)
- Potential compatibility issues with newer iOS versions
Code Examples
- Initializing the RichEditorView:
let editorView = RichEditorView(frame: view.bounds)
view.addSubview(editorView)
- Setting up the toolbar:
let toolbar = RichEditorToolbar(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44))
toolbar.options = RichEditorDefaultOption.all
toolbar.editor = editorView
editorView.inputAccessoryView = toolbar
- Applying text formatting:
editorView.bold()
editorView.italic()
editorView.underline()
editorView.setTextColor(.red)
- Getting and setting HTML content:
// Set HTML content
editorView.html = "<p>Hello, <b>world</b>!</p>"
// Get HTML content
let htmlContent = editorView.html
Getting Started
To integrate RichEditorView into your iOS project:
-
Add the following to your Podfile:
pod 'RichEditorView'
-
Run
pod install
in your terminal. -
Import the library in your Swift file:
import RichEditorView
-
Create and configure a RichEditorView instance:
let editorView = RichEditorView(frame: view.bounds) view.addSubview(editorView) let toolbar = RichEditorToolbar(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44)) toolbar.options = RichEditorDefaultOption.all toolbar.editor = editorView editorView.inputAccessoryView = toolbar
-
Use the editor in your app:
editorView.html = "<p>Start editing here...</p>"
Competitor Comparisons
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
Pros of ZSSRichTextEditor
- More comprehensive set of rich text editing features, including text alignment, indentation, and lists
- Built-in support for image insertion and manipulation
- Customizable toolbar with a wider range of formatting options
Cons of ZSSRichTextEditor
- Less actively maintained, with the last update being several years ago
- More complex implementation, which may lead to a steeper learning curve
- Larger codebase, potentially increasing the app's size and complexity
Code Comparison
ZSSRichTextEditor:
let richTextEditor = ZSSRichTextEditor()
richTextEditor.setHTML("Initial content")
richTextEditor.delegate = self
view.addSubview(richTextEditor)
RichEditorView:
let richEditorView = RichEditorView(frame: view.bounds)
richEditorView.html = "Initial content"
richEditorView.delegate = self
view.addSubview(richEditorView)
Both libraries offer similar basic setup, but ZSSRichTextEditor provides more built-in functionality out of the box, while RichEditorView offers a simpler, more lightweight implementation. The choice between the two depends on the specific requirements of your project, such as the need for advanced formatting options versus a more streamlined, easier-to-maintain solution.
Integrate iCloud into iOS document projects with one-line code methods. Sync, upload, manage, and remove documents from iCloud quickly and easily. Helps to make iCloud "just work" for developers too.
Pros of iCloudDocumentSync
- Focuses specifically on iCloud document synchronization, providing a dedicated solution for this use case
- Offers built-in support for handling conflicts and merging changes in synchronized documents
- Includes features for managing document versions and metadata
Cons of iCloudDocumentSync
- Limited to iCloud synchronization, lacking support for other cloud storage services
- May require more setup and configuration compared to a simpler rich text editor
- Less actively maintained, with fewer recent updates and contributions
Code Comparison
RichEditorView:
let editor = RichEditorView(frame: view.bounds)
editor.html = "<h1>Hello World!</h1>"
editor.placeholder = "Type some text..."
view.addSubview(editor)
iCloudDocumentSync:
let document = iCloudDocument(fileURL: fileURL)
document.save(to: fileURL, for: .forOverwriting) { success in
if success {
print("Document saved successfully")
}
}
While RichEditorView focuses on providing a rich text editing interface, iCloudDocumentSync is centered around document synchronization with iCloud. The code examples highlight these different focuses, with RichEditorView demonstrating the creation and customization of a rich text editor, and iCloudDocumentSync showing document saving and synchronization functionality.
Fully open source text editor for iOS written in SwiftUI.
Pros of Edhita
- Full-featured text editor with syntax highlighting for multiple languages
- Supports file management and directory structure
- Includes a built-in web server for previewing HTML files
Cons of Edhita
- Less focused on rich text editing compared to RichEditorView
- May have a steeper learning curve due to its broader feature set
- Not specifically designed for integration into other iOS apps
Code Comparison
RichEditorView:
let editor = RichEditorView(frame: self.view.bounds)
editor.html = "<h1>My Awesome Content</h1>"
editor.placeholder = "Type some text..."
Edhita:
let textView = SyntaxTextView()
textView.text = "# My Awesome Content"
textView.language = .markdown
While RichEditorView focuses on HTML-based rich text editing, Edhita provides a more general-purpose text editing experience with syntax highlighting for various languages. RichEditorView is better suited for applications requiring rich text input, while Edhita is more appropriate for code editing and file management tasks.
📝 The next in the generations of 'growing textviews' optimized for iOS 8 and above.
Pros of NextGrowingTextView
- Lightweight and focused on growing text view functionality
- Written in Swift, making it more modern and potentially easier to integrate into Swift projects
- Simpler implementation, which may lead to better performance for basic text input scenarios
Cons of NextGrowingTextView
- Lacks rich text editing features (e.g., formatting, image insertion)
- Limited customization options compared to RichEditorView
- May require additional work to implement more advanced text editing functionality
Code Comparison
RichEditorView:
let editorView = RichEditorView(frame: self.view.bounds)
editorView.html = "<h1>Hello World!</h1>"
editorView.placeholder = "Type some text..."
self.view.addSubview(editorView)
NextGrowingTextView:
let growingTextView = NextGrowingTextView(frame: self.view.bounds)
growingTextView.placeholderAttributedText = NSAttributedString(string: "Type some text...")
self.view.addSubview(growingTextView)
Both libraries offer easy setup, but RichEditorView provides more initial functionality for rich text editing, while NextGrowingTextView focuses on the growing aspect of the text view. RichEditorView may be better suited for projects requiring advanced text editing features, while NextGrowingTextView could be ideal for simpler, performance-focused implementations.
⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features
Pros of SlackTextViewController
- More comprehensive feature set, including auto-growing text views and custom input accessory views
- Better performance optimization for large message lists
- Active development and maintenance by Slack, a major tech company
Cons of SlackTextViewController
- Focused primarily on chat-style interfaces, less flexible for other rich text editing scenarios
- Steeper learning curve due to more complex architecture
- Objective-C based, which may be less appealing for Swift-only projects
Code Comparison
SlackTextViewController:
SLKTextViewController *textViewController = [SLKTextViewController new];
textViewController.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
textViewController.bounces = NO;
textViewController.keyboardPanningEnabled = YES;
textViewController.inverted = YES;
RichEditorView:
let richEditorView = RichEditorView(frame: self.view.bounds)
richEditorView.delegate = self
richEditorView.placeholder = "Type some text..."
richEditorView.inputAccessoryView = toolbar
self.view.addSubview(richEditorView)
SlackTextViewController provides a more comprehensive solution for chat-like interfaces with built-in features for message handling and keyboard management. RichEditorView, on the other hand, offers a simpler and more focused approach to rich text editing, making it easier to integrate into various app types. The choice between the two depends on the specific requirements of your project and the level of customization needed.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
RichEditorView has been archived. I do not plan on making updates to it.
This project was needed for an app I was working on in the mid 2010's. I haven't needed it for a long time, and don't expect to need it in the future. You shouldn't either.
This project depends on UIWebView which was deprecated in iOS 12. While it's possible to change it to use WKWebView, it's not a straightforward find-and-replace. For example, some methods that used to be synchronous are now asynchronous.
There are forks that have made the migration. I would encourage you to check those out and see if one suits your needs.
RichEditorView
RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing.
Written in Swift 4
Supports iOS 8+ through Cocoapods or Carthage.
- Looking for Android? Check out wasabeef/richeditor-android
Seen in Action
Just clone the project and open RichEditorViewSample/RichEditorViewSample.xcworkspace
in Xcode.
Features
- Bold
- Italic
- Subscript
- Superscript
- Strikethrough
- Underline
- Justify Left
- Justify Center
- Justify Right
- Heading 1
- Heading 2
- Heading 3
- Heading 4
- Heading 5
- Heading 6
- Undo
- Redo
- Ordered List
- Unordered List
- Indent
- Outdent
- Insert Image
- Insert Link
- Text Color
- Text Background Color
Installation
Cocoapods
If you have Cocoapods installed, you can use Cocoapods to include RichEditorView
into your project.
Add the following to your Podfile
:
pod "RichEditorView"
use_frameworks!
Note: the use_frameworks!
is required for pods made in Swift.
Carthage
Add the following to your Cartfile
:
github 'cjwirth/RichEditorView'
Using RichEditorView
RichEditorView
makes no assumptions about how you want to use it in your app. It is a plain UIView
subclass, so you are free to use it wherever, however you want.
Most basic use:
editor = RichEditorView(frame: self.view.bounds)
editor.html = "<h1>My Awesome Editor</h1>Now I am editing in <em>style.</em>"
self.view.addSubview(editor)
Editing Text
To change the styles of the currently selected text, you just call methods directly on the RichEditorView
:
editor.bold()
editor.italic()
editor.setTextColor(.red)
If you want to show the editing toolbar RichEditorToolbar
, you will need to handle displaying it (KeyboardManager.swift
in the sample project is a good start). But configuring it is as easy as telling it which options you want to enable, and telling it which RichEditorView
to work on.
let toolbar = RichEditorToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 44))
toolbar.options = RichEditorDefaultOption.all
toolbar.editor = editor // Previously instantiated RichEditorView
Some actions require user feedback (such as select an image, choose a color, etc). In this cases you can conform to the RichEditorToolbarDelegate
and react to these actions, and maybe display some custom UI. For example, from the sample project, we just select a random color:
private func randomColor() -> UIColor {
let colors: [UIColor] = [
.red, .orange, .yellow,
.green, .blue, .purple
]
let color = colors[Int(arc4random_uniform(UInt32(colors.count)))]
return color
}
func richEditorToolbarChangeTextColor(toolbar: RichEditorToolbar) {
let color = randomColor()
toolbar.editor?.setTextColor(color)
}
Advanced Editing
If you need even more flexibility with your options, you can add completely custom actions, by either making an object that conforms the the RichEditorOption
protocol, or configuring a RichEditorOptionItem
object, and adding it to the toolbar's options:
let clearAllItem = RichEditorOptionItem(image: UIImage(named: "clear"), title: "Clear") { toolbar in
toolbar?.editor?.html = ""
return
}
toolbar.options = [clearAllItem]
Author
Caesar Wirth - cjwirth@gmail.com
@cjwirthAcknowledgements
- wasabeef/richeditor-android - Android version of this library (Apache v2)
- nnhubbard/ZSSRichTextEditor - Inspiration and Icons (MIT)
License
RichEditorView is released under the BSD 3-Clause License. See LICENSE.md for details.
Top Related Projects
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
Integrate iCloud into iOS document projects with one-line code methods. Sync, upload, manage, and remove documents from iCloud quickly and easily. Helps to make iCloud "just work" for developers too.
Fully open source text editor for iOS written in SwiftUI.
📝 The next in the generations of 'growing textviews' optimized for iOS 8 and above.
⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot