ios - Stop removal of default text in textview (Swift) -


if have uitextview following text:

"please finish sent..."

and aim allow user edit textview can finish sentence, how can make can't remove text there before start editing aka "please finish sent"?

update: have been able make users cannot remove initial text, there way make cannot type before initial text or inside it? has answered far!

update: solved. stop people editing before , inside string added

if range.location == 0 {             return false         }  if (0 < range.location && range.location < count(string.utf16)) == true {             return false         } 

to shouldchangetextinrange function. help!

this way can stop user remove initial text:

import uikit  class viewcontroller: uiviewcontroller, uitextviewdelegate {      @iboutlet weak var textv: uitextview!      override func viewdidload() {         super.viewdidload()         textv.text = "please finish sent"  //set default text.         textv.delegate = self     }      func textview(textview: uitextview, shouldchangetextinrange range: nsrange, replacementtext text: string) -> bool {          let  char = text.cstringusingencoding(nsutf8stringencoding)!         let isbackspace = strcmp(char, "\\b")          if (isbackspace == -92) {             // if backspace pressed call             if textv.text == "please finish sent" {                 return false             }         }         return true     } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -