UITextView添加placeholder

使用UITextView 代理方法

- (void)textViewDidBeginEditing:(UITextView *)textView { 
  if ([textView.text isEqualToString:@"placeholder text here..."]) { 
      textView.text = @""; 
      textView.textColor = [UIColor blackColor]; //optional 
   }
  [textView becomeFirstResponder];
}
- (void)textViewDidEndEditing:(UITextView *)textView { 
  if ([textView.text isEqualToString:@""]) { 
      textView.text = @"placeholder text here..."; 
      textView.textColor = [UIColor lightGrayColor]; //optional 
  } 
  [textView resignFirstResponder];
}

你可能感兴趣的:(UITextView添加placeholder)