How to add text bubble styles when I separate the email address by comma as show in the screen shot attached

170 Views Asked by At

Hi I'm new to iOS app development. I am implemented an UITextview to add multiple address separated by comma I need to apply a style bubble when user separates the email by pressing comma or space or done button (in the keyboard.) reference screen shot from android

I am executing an email array same as below

func executeEmailArray(){
        self.emailString = self.emailTF.text ?? ""
        self.emailArray = emailString.components(separatedBy: ",")
        print("emailArray \(self.emailArray)")
    }

I formatted the uiTextView as below by using an extension

extension NewShoppingListVC: UITextViewDelegate {
func textViewDidChangeSelection(_ textView: UITextView) {
    // Moves cursor to start when tapped on textView with placeholder
    if emailTF.text == placeholder {
        emailTF.selectedRange = start
    }
}
func textViewDidChange(_ textView: UITextView) {
    // Manages state of text when changed
    if emailTF.text.isEmpty {
        emailTF.text = placeholder
        emailTF.textColor = .lightGray
    } else if emailTF.text != placeholder {
        emailTF.textColor = .black
    }
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
    // Called when you're trying to enter a character (to replace the placeholder)
    if emailTF.text == placeholder {
        emailTF.text = ""
    }
    return true
}

}

Please add some codes to explain me how to apply the textbubbles as in the image

0

There are 0 best solutions below