Giter Site home page Giter Site logo

cjwirth / richeditorview Goto Github PK

View Code? Open in Web Editor NEW
1.9K 1.9K 445.0 1.86 MB

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

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

Objective-C 9.26% Ruby 1.27% Swift 64.64% HTML 1.67% JavaScript 21.32% CSS 1.85%

richeditorview's Introduction

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

License: BSD 3 Cocoapods Carthage compatible

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

Written in Swift 4

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 = 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 - [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

ccwasden avatar cjwirth avatar halilb avatar jesiegel1 avatar mfrawley avatar shizunaito avatar steviemo avatar stranfb avatar wirthcaesar avatar zummenix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

richeditorview's Issues

REV toolbar appears for other input views

I have a problem. I have a text field above a REV and when I click on REV, than on my text field, the REV panel is still showing above the keyboard. Is there a way how to lost focus of REV and dissapear of REV panel?

Auto-suggest with @usernames and #hashtags

I'd like the user to be able to enter HTML text (actually just Bold and Italic), and @usernames and #hashtags - with the @usernames and #hashtags autosuggested underneath the text-entry.

There are a number of third-party libraries which help with this:
https://github.com/arsonic/AVTagTextView
https://github.com/AdamBCo/ABCAutoCompleteTextView
https://github.com/Mazyod/MJAutoComplete

(all objective-c)

@cjwirth - would you recommend trying to meld RichEditorView with one of these libraries, or is it something that could be added to RichEditorView?

I can't textColor by using `setTextColor`

I have called RichEditorView.setTextColor on richEditorDidLoad.

When it call I have passed redColor, but text color is still grayColor?
How can I change it?

And can you add method to set font family, line-height for customized style in your style.css, ...?
It is very difficult to customize css.

Cant share word from RichEditorView

Hello.

When I try to use "share" button from context menu(long tap on the any word) and choose Twitter or Messages and tap on Cancel button on Share Controller - I cant can no longer interact with application.
I tried to disable share button by creating UIWebView child with canPerformAction method that returns false but it doesn't work too.

How can I disable button or fix this behaviour?

hbnvfbbjoik

editor view's web view doesn't retrieve image file from Documents folder

Hi,
this might not be directly related to this framework, but maybe someone can give me a hint to the right direction to take for solving this problem.

When I try to insert an image like so:
toolbar.editor!.insertImage(fileURL.absoluteString, alt: "new image")

all works fine.

The image data is written to a file in the documents folder and then the refreshed html contains the image tag with the image path.

However, after I stop the simulator and restart it, the image can't be loaded into the html of the editor's web view properly.

See the screenshots below. The image tag in the html looks like this
image

I have checked in the finder that the file is there... it has been saved indeed. doesn't matter if I convert the ui image to jpg or to png.
The weird thing is that when creating the the file, the web view has to update as well and retrieve the file from the documents folder. Otherwise it wouldn't show.... the html string is properly retrieved from core data, otherwise there would not be any text with html text attributes.

screen shot 2016-05-13 at 17 10 06

screen shot 2016-05-13 at 17 08 37

Other font

Is there any change of using any other than default font with RichEditView?

Setting background transparent not working

I tried to set the background to a clear color using this code:

override func viewDidLoad() {
        super.viewDidLoad()

        headerLabel.text = data.header
        contentTextView.editingEnabled = false
        contentTextView.delegate = self
        contentTextView.setHTML(data.content)
    }

func richEditorDidLoad(editor: RichEditorView) {
        contentTextView.backgroundColor = UIColor.clearColor()
        contentTextView.webView.backgroundColor = UIColor.clearColor()
        contentTextView.webView.opaque = false
        contentTextView.inputAccessoryView?.backgroundColor = UIColor.clearColor()
    }

But after appearing the view looks like this:
simulator screen shot 09 may 2016 17 31 29

If i rotate the view and rotate it back the view looks correct like this:
simulator screen shot 09 may 2016 17 31 33

Seems like it is some kind of redraw error! Any combination of setNeedsToDisplay() and layoutIfNeeded() did not work.

The HTML code:
<h1 style="color: rgb(256, 0, 0);"><font size="3"><span style="font-weight: normal; -webkit-text-size-adjust: 100%;">Simply press the</span><span style="-webkit-text-size-adjust: 100%;"> + </span><span style="font-weight: normal; -webkit-text-size-adjust: 100%;">button in the main view and a new recipe base on the default template will be created!</span></font></h1>

Any idea why webview is acting like this?

WKWebView?

At some point Apple will drop support for UIWebView. Are there any reasons why this component can't use WKWebView currently?

i want to use the richTextView to replace the funtion of UITextView to show HTML string

i want to use the richTextView to replace the funtion of UITextView to show HTML string . After i set HTML string to richTextView,how could i get the textView height? if the HTML string contain remote image, will the height be calculate correct? i

public private(set) var editorHeight: Int = 0 {
        didSet {
            delegate?.richEditor?(self, heightDidChange: editorHeight)
        }
    }

will this method working ?

Add option to change toolbar tintColor

i want to use my picture to replace the picture at your project. such as bold,undo. i delete your picture and insert my own picture. it does not work. why?

Question: Is there a reason clipsToBounds is set to false on the scrollView?

In the setup function for the RichEditorView class, the scrollView has its clipsToBounds property set to false:

https://github.com/cjwirth/RichEditorView/blob/master/RichEditorView/Classes/RichEditorView.swift#L153

This causes a problem for my particular usage of the RichEditorView. It causes the content in the editor to scroll over other controls I have in my view. If I set it to false it "fixes" the issue.

I'm not experienced enough with Swift/iOS programming to know if this will cause bizarre and unpredictable effects on other aspects of the RichEditorView. It seems to work fine, but I was curious if there was a larger reason to set clipsToBounds to false.

Change of background color

Hello,
I am pretty desperate. I just can't figure out how can I change background color of webview. It is white, I want a clear color.

How to pre-set HTML

Hi there,

First off, I wanted to thank you for your fantastic work and dedication to this project and for being incredibly active! I couldn't have been happier to find RichEditorView as I have been looking for a more updated version of the original ZSSRichTextEditor for some time.

My problem:
I want to set the HTML of my REV on initialization so that it opens with the HTML already set (passed in from another VC).

My setup is as follows:
I have a VC that manages the entire parent view (with some additional UI/actions) and an embedded container view that has it's own VC whose responsibility is to manage the actual REV.

Parent VC (Obj-C):

@property (strong, nonatomic) LessonViewController *lessonViewController;
- (void)prepareForSegue { // embedSegue
    ...
    self.lessonViewController = (LessonViewController *)segue.destinationViewController;
    self.lessonViewController.lessonContents = self.lesson.contents; // where lesson is a data model

REV VC (Swift):

@objc public class LessonViewController: UIViewController {
    @IBOutlet weak var editorView: RichEditorView!
    public var lessonContents: String = "" {
        didSet {
            editorView.setHTML(lessonContents)
        }

This causes an unexpectedly found nil while unwrapping an Optional value. Doing some debugging, it turns out that in the didSet, the editorView is nil at that moment. I'm not sure why that is (the outlet is properly hooked up in IB). I've also tried calling editorView.setHTML() in a separate method and not in the didSet { } but I run into the same issue.

Any insight would be greatly appreciated, and perhaps you have another way you'd recommend pre-setting the HTML of REV before it opens, with the HTML being passed in from a different VC.

Focus RichEditorView when view is tapped

How can I take a focus when I click on the REV window? For now, I can write to REV input view only if I click on the first row. I want to take a focus (start writing) after I click anywhere on the input view of REV.

Thanks for help.

Placeholder doesn't disappear.

When I click orderedList, placeholder still appears.(without any character)
Only when I input any character, it disappears.

Can't specify a baseURL?

Hello

I'm trying to load a local image into the webview that image using a relative path. But I cannot find a way to specify a baseURL :( Any idea?

Toolbar isn't a proper accessory

Since the RichEditorToolbar isn't an accessory view to UIWebView (a really annoying problem; "Hacking Accessory Hiding" reference), the toolbar will overlap onto the editing view.

Find new way to hide default keyboard toolbar

The relatively common technique of hiding UIWebView's input accessory view that we are using in CJWWebView+HackishAccessoryHiding.m is most definitely a horrible piece of code. Not only that but recently it has been getting apps rejected from the app store which is an outcome nobody wants.

Look into seeing if there is a better way to hide and/or cover up the input accessory view. Maybe this means upgrading to WKWebView, I don't really know.

This is a bad, brittle, dangerous piece of code, and I would really like to get it out of the codebase.

hello.

Hi.
If I want to use in OC.
What should I do ?
Can you give some hints?
Thank you very much.
Good luck to you!

RichEditorView can't show text

use the editor.setHTML function can't show the text from server, but can show the text in form just like in the readme text, it's weird, did I miss something??

Objective-C Support

The component is great and awesome and it's a breeze to use in Swift.

However, I faced with a problem while adding it to existing objective-с class - I can't make Xcode see the corresponding class.

If I just use the @class directive, the complier says it's a forward class declaration.

I suspect that we just can't use this great library in Objective-C which is a huge downside. Am I wrong?

Done button

Is there a way how can I add a Done button to REV? I mean if you type on UITextField, the original Apple keyboard shows up and there is a done button in right down corner. But REV has only return.

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.