美文网首页
带placeholder的textView

带placeholder的textView

作者: 0x00chen | 来源:发表于2016-09-03 16:33 被阅读58次

一种简单的方式实现带placeholder的textview,网上很多方法可以实现,这是在stackoverflow上面看到的一位回答者写的,感觉跟简洁,写下来记录一下。

下面贴出关键代码:

textView初始化:

    self.textView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.textView.layer.borderWidth = .5f;
    self.textView.text = @"请填写跟进计划...";
    self.textView.textColor = [UIColor lightGrayColor];

代理方法:

- (void)textViewDidBeginEditing:(UITextView *)textView{
    
    if ([textView.text isEqualToString:@"请填写跟进计划..."]) {
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
    [textView becomeFirstResponder];
    
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    
    if ([textView.text isEqualToString:@""]) {

        textView.text = @"请填写跟进计划...";
        textView.textColor = [UIColor lightGrayColor];
    }
    [textView resignFirstResponder];
}

相关文章

网友评论

      本文标题:带placeholder的textView

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