开发者

How to prevent user to editing from given range in iPhone textView

开发者 https://www.devze.com 2023-01-18 08:37 出处:网络
I am currently wo开发者_运维百科rked on simple textview application in which I need prevent user to write data in textView & after preventing he may be change other value of textview. Below is my

I am currently wo开发者_运维百科rked on simple textview application in which I need prevent user to write data in textView & after preventing he may be change other value of textview. Below is my code for prevernting user to write into textview.

- (void)textViewDidChange:(UITextView *)textView
{
    NSString *textValue=textView.text;
    NSInteger intLen=[textValue length];
    if(intlen>280){
      textView.editable=No; 
    }
    else
    {   
      textView.editable=YES;    
      if(intLen <=140)
      {
        intLen=140-intLen;
        intSMSValue=1;
        lblSmscounter.text=[[NSNumber numberWithInt:intSMSValue]stringValue];
            lblCountChar.text=[[NSNumber numberWithInt:intLen] stringValue]; 
     }
     if((intLen>140)&&(intLen <=280))
     {
        intLen=280-intLen;
        intSMSValue=2;
        lblSmscounter.text=[[NSNumber numberWithInt:intSMSValue]stringValue];
        lblCountChar.text=[[NSNumber numberWithInt:intLen] stringValue];        
     }
   }
}

But in my code I am prevent user to write more than 280 bt user caneditable the previous text.


Try delegate method

  • (BOOL)textView:(UITextView )textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString)text{

}

If the range of editable text is ok, return yes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号