GithubHelp home page GithubHelp logo

jaumdx / richeditorview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cjwirth/richeditorview

0.0 1.0 0.0 1.81 MB

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

License: BSD 3-Clause "New" or "Revised" License

Ruby 1.05% JavaScript 18.57% HTML 1.47% CSS 1.63% Objective-C 9.40% Swift 56.21% Shell 11.67%

richeditorview's Introduction

RichEditorView

License: BSD 3 Cocoapods Carthage compatible

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

Written in Swift 3.0

Supports iOS 8+ through Cocoapods or Carthage.

Seen in Action

Demo

Just clone the project and open RichEditorViewSample/RichEditorViewSample.xcworkspace in Xcode.

Features

Toolbar Demo

  • 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 = 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:

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 - [email protected]

@cjwirth on Twitter @cjwirth

Acknowledgements

License

RichEditorView is released under the BSD 3-Clause License. See LICENSE.md for details.

richeditorview's People

Contributors

cjwirth avatar jesiegel1 avatar mfrawley avatar wirthcaesar avatar zummenix avatar ccwasden avatar halilb avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.