Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Emojis #2

Open
Amir-OffsureIt opened this issue Jun 5, 2018 · 2 comments
Open

Not working with Emojis #2

Amir-OffsureIt opened this issue Jun 5, 2018 · 2 comments

Comments

@Amir-OffsureIt
Copy link

Whenever User enter emoji App is getting crashed.

@bhaveshlsamcom
Copy link

@sumitjagdev @Amir-OffsureIt yes getting crashed while adding emoji
any solution for that please?

@SreelekhN
Copy link

@sumitjagdev

func validateForTagsColor() {
let cursorIndex = self.curserPosition()
guard !self.text.isEmpty else { return }

    let string = NSMutableAttributedString(string: self.text)
    string.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.white, range: NSRange(location: 0, length: string.length))
    string.addAttribute(NSAttributedString.Key.font, value: UIFont.appFont(.regular, size: 14), range: NSRange(location: 0, length: string.length))

    var index = self.text.startIndex
    while index < self.text.endIndex {
        let character = self.text[index]
        if character == "@" || character == "#" {
            var endIndex = index
            while endIndex < self.text.endIndex && !self.text[endIndex].isWhitespace && self.text[endIndex] != "\n" {
                endIndex = self.text.index(after: endIndex)
            }
            let range = NSRange(index..<endIndex, in: self.text)
            string.addAttribute(NSAttributedString.Key.font, value: UIFont.appFont(.medium, size: 14), range: range)
            index = endIndex
        } else {
            index = self.text.index(after: index)
        }
    }
    
    self.attributedText = string
    self.setCurserAtPosition(position: cursorIndex)
}

use this code, its working for me

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

No branches or pull requests

3 participants