0

I have one Uitextview

i have one code like this in Text String color Purple

 let titleAttributes = [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.headline), NSAttributedStringKey.foregroundColor: UIColor.purple]

            let titleString = NSAttributedString(string: "Hello World", attributes: titleAttributes)
            txtEditor.attributedText = titleString

after this code i want to write in (real time) with uitextview but in Black Color for example in this function i need to write

func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {

return true
    }

How can i write in other color in continue of this textView

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • Probably duplicate of https://stackoverflow.com/questions/16423632/how-to-allow-nsattributedstring-text-be-typed-into-a-uitextview – matt Feb 08 '18 at 15:24
  • 1
    Possible duplicate of [How to allow NSAttributedString text be typed into a UITextView?](https://stackoverflow.com/questions/16423632/how-to-allow-nsattributedstring-text-be-typed-into-a-uitextview) – Owen Hartnett Feb 08 '18 at 18:56

1 Answers1

1

To configure the color in which the user will type, set the text view’s typing attributes.

https://developer.apple.com/documentation/uikit/uitextview/1618629-typingattributes

matt
  • 515,959
  • 87
  • 875
  • 1,141