ios - Updating UITextView autocapitalizationType dynamically -


i've got blank test application uitextview, , i've added delegate method:

func textviewdidchange(textview: uitextview) {     if textview.text.hasprefix("cap") {         textview.autocapitalizationtype = .allcharacters     } else {         textview.autocapitalizationtype = .sentences     } } 

if user types "cap" @ start of text, want textview change .allcharacters autocapitalizationtype. if remove prefix, should change sentences.

the code called not honoured , keyboard doesn't change reflect this. idea how can nudge textview update caps?

very interesting question. in fact autocapitalizationtype doesn't change while keyboard present can nudge resigning , making become first responder again:

textview.autocapitalizationtype = .allcharacters // slow operation textview.resignfirstresponder()  textview.becomefirstresponder() 

the problem process slow feel big delay between every character should operation once.

func textviewdidchange(textview: uitextview) {     if textview.text.hasprefix("cap") {         if textview.autocapitalizationtype != .allcharacters {             textview.autocapitalizationtype = .allcharacters             textview.resignfirstresponder()             textview.becomefirstresponder()         }     } else {         textview.autocapitalizationtype = .sentences     } }  

i hope helps.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -