1.先遵循UITextViewDelegate协议
2.设置全局变量textLable或者自定义一个UITextView,将lable设置为其属性
3.以下代码
#pragma mark -
#pragma mark 给UITextView添加placeholder
// 设置代理人
content.delegate = self;
// 给UITextView添加标签
textLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 20)];
textLable.text = @"请在此处输入正文";
textLable.enabled = NO;
textLable.backgroundColor = [UIColor clearColor];
[content addSubview:textLable];
}
// 添加textView的方法
- (void)textViewDidChange:(UITextView *)textView
{
// NSLog(@"输出啦啦啦");
if (content.text.length == 0) {
textLable.text = @"请在此处输入正文";
} else {
textLable.text = @"";
}
}