0

I want to achieve this kind of style in UITextView same like WhatsApp, Facebook and Instagram status. Where we can add a background color to text only parts and it will expand if we continue writing it.

Here is the image for more details. :

Here is the image for more details.

Jayesh Thanki
  • 2,037
  • 2
  • 23
  • 32

1 Answers1

-1

Write following code in UITextViewDelegate method. On each word the textview delegate get call and you can apply the background color for textview text.

var attributedString = NSMutableAttributedString(string: textField.text)
attributedString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.clear, range: NSRange(location: 0, length: textField.text.length))
textField.attributedText = attributedString
  • Thanks Bhushan for the response but i don't wants the image, I wants textview which having the feature to apply background color to text, something like the image that i have attached in my quetion. – iOS Trainee. May 18 '18 at 09:26