Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Update README for Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cjwirth committed Jun 17, 2017
1 parent 447e3b3 commit c321652
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ RichEditorView

RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing.

Written in Swift 2.0 (Xcode 7.0)
Written in Swift 3.0

Supports iOS 8 and 9 through Cocoapods or Carthage.
Supports iOS 8+ through Cocoapods or Carthage.

- _Looking for Android? Check out_ [wasabeef/richeditor-android](https://github.com/wasabeef/richeditor-android)

Expand Down Expand Up @@ -54,7 +54,7 @@ Installation

#### Cocoapods

If you have Cocoapods 0.36+ installed, you can use Cocoapods to include `RichEditorView` into your project.
If you have Cocoapods installed, you can use Cocoapods to include `RichEditorView` into your project.
Add the following to your `Podfile`:

```
Expand All @@ -81,7 +81,7 @@ Most basic use:

```
editor = RichEditorView(frame: self.view.bounds)
editor.setHTML("<h1>My Awesome Editor</h1>Now I am editing in <em>style.</em>")
editor.html = "<h1>My Awesome Editor</h1>Now I am editing in <em>style.</em>"
self.view.addSubview(editor)
```

Expand All @@ -91,28 +91,24 @@ To change the styles of the currently selected text, you just call methods direc
```Swift
editor.bold()
editor.italic()
editor.setTextColor(UIColor.redColor())
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.

```Swift
let toolbar = RichEditorToolbar(frame: CGRectMake(0, 0, 320, 44))
toolbar.options = RichEditorOptions.all()
let toolbar = RichEditorToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 44))
toolbar.options = RichEditorOptions.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:

```Swift
private func randomColor() -> UIColor {
let colors = [
UIColor.redColor(),
UIColor.orangeColor(),
UIColor.yellowColor(),
UIColor.greenColor(),
UIColor.blueColor(),
UIColor.purpleColor()
let colors: [UIColor] = [
.red, .orange, .yellow,
.green, .blue, .purple
]

let color = colors[Int(arc4random_uniform(UInt32(colors.count)))]
Expand All @@ -131,7 +127,7 @@ If you need even more flexibility with your options, you can add completely cust

```Swift
let clearAllItem = RichEditorOptionItem(image: UIImage(named: "clear"), title: "Clear") { toolbar in
toolbar?.editor?.setHTML("")
toolbar?.editor?.html = ""
return
}
toolbar.options = [clearAllItem]
Expand Down

0 comments on commit c321652

Please sign in to comment.