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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -