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

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -