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
Post a Comment