ios - Change 'Return' button function to 'Done' in swift in UITextView -


i rid of "return" function of keyboard while user typing, there no new lines, instead 'return' key function 'done' hide keyboard.

i using uitextview, editable, user able type post, , post main timeline, since have fixed cells, don't want user able press 'return' , post out of range of timeline.

i found works uitextfield, not uitextview:

func textfieldshouldreturn(textfield: uitextfield!) -> bool {     textfield.resignfirstresponder()  //if desired     return true } 

so wanted know if there way in uitextview, or @ least able hide keyboard if pressed return, instead of creating new line.

you can set return key type of text field:

textfield.returnkeytype = uireturnkeytype.done 

update can use same approach set return key "done", mentioned above. however, uitextview doesn't provide callback when user hits return key. workaround, can try handle textview(textview: uitextview, shouldchangetextinrange range: nsrange, replacementtext text: string) delegate call, , dismiss keyboard when detect input of new line character:

func textview(textview: uitextview, shouldchangetextinrange range: nsrange, replacementtext text: string) -> bool {     if (text == "\n") {         textview.resignfirstresponder()     }     return true } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -