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' -

java - Log4j2 configuration not found when running standalone application builded by shade plugin -

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