美文网首页
UITextView添加placeholder

UITextView添加placeholder

作者: 出门请右拐 | 来源:发表于2016-08-11 09:05 被阅读16次

使用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

      本文链接:https://www.haomeiwen.com/subject/panjsttx.html