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

how to limit text count in the editor? #212

Closed
RaviPulpstrategy opened this issue Sep 6, 2019 · 5 comments
Closed

how to limit text count in the editor? #212

RaviPulpstrategy opened this issue Sep 6, 2019 · 5 comments

Comments

@RaviPulpstrategy
Copy link

No description provided.

@jahid1297
Copy link

@RaviPulpstrategy did you found any solution ?

@RaviPulpstrategy
Copy link
Author

@RaviPulpstrategy did you found any solution ?

Not yet!

@YoomamaFTW
Copy link

Did you try checking the RichEditorDelegate? Here's what I've got:

var prevText: String!
@objc func richEditor(_ editor: RichEditorView, contentDidChange content: String) {
    if content.count > 20 {
        editor.html = prevText 
        // Where content is the HTML, not the visible text and 20 is the max number of characters
    } else {
        prevText = content
    }
}

I just started iOS development, so I'm not sure if this'll cause any issues regarding threading. I haven't tested copy and paste, but it should work just fine since the previous text onTextChange is saved in the variable.

Cheers!

@YoomamaFTW
Copy link

YoomamaFTW commented Oct 27, 2019

@RaviPulpstrategy @jahid1297

https://gist.github.com/YoomamaFTW/6f436e17f34f43ebda13e08d629e9d56

This is if you want the full code (it has some other issue I had, so sorry for the clump). The gist is the full programmatically made view controller of an editor view controller. The comment's code itself is the same for both storyboard and programmatically.

Do note: Make sure when you're inheriting classes that you also inherit RichEditorDelegate, so like this:

class EditorViewController: UIViewController, RichEditorDelegate {
    let editorView = RichEditorView()
    var prevText: String!
    override viewDidLoad() {
        super.viewDidLoad()
        editorView.delegate = self
        // Some other stuff
    }

    @objc func richEditor(_ editor: RichEditorView, contentDidChange content: String) {
        if content.count > 20 {
            editor.html = prevText 
            // Where content is the HTML, not the visible text and 20 is the max number of characters
        } else {
            prevText = content
        }
    }
}

@RaviPulpstrategy
Copy link
Author

Yes, it will work!
Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants