I'm working on a iOS app with Swift. And I have to implement multiple colors for text in UITextField. So far I know how to set color for different parts of UITextField text and how to concatenate them. This is the example of that:
let attributedString = NSMutableAttributedString(string: string, attributes: [:])
attributedString.addAttribute(NSForegroundColorAttributeName,
value: color,
range: NSRange(location: 0, length: string.characters.count))
But when I press delete button and erase some of the text, and when I start wright again, the new text has the color of the last deleted text. I want default color for every new character, regardless which was the last color (color of text when deleting) for text in UITextField. Can I set color or some attribute of text (new text) in this function?
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
So, when new character has been written it will be in my desired color, black for instance. Thanks for your answers.