Placeholder in UITextView

前端 未结 30 3060
野趣味
野趣味 2020-11-22 16:01

My application uses an UITextView. Now I want the UITextView to have a placeholder similar to the one you can set for an UITextField.<

30条回答
  •  长情又很酷
    2020-11-22 16:17

    Simple way to use this within some line of code:

    Take one label up to UITextView in .nib connecting this label to your code , After it.

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
        if (range.location>0 || text.length!=0) {
            placeholderLabel1.hidden = YES;
        }else{
            placeholderLabel1.hidden = NO;
        }
        return YES;
    }
    

提交回复
热议问题