1.把UITextView的text属性当成“placeholder”使用。
2.在开始编辑的代理方法里清除“placeholder”。
3.在结束编辑的代理方法里根据条件设置“placeholder”。
这种方法有一个缺点是:用户点击textview时,placeholder就会消失
// 创建textView
UITextView *textView =[[UITextViewalloc] initWithFrame:CGRectMake(20,70,200,100)];
textView.backgroundColor= [UIColor whiteColor];
textView.text = @"请输入信息";
textView.textColor = [UIColor grayColor];
textView.delegate = self;
[self.view addSubview:textView];
- (void)textViewDidEndEditing:(UITextView *)textView
{
if(textView.text.length < 1){
textView.text = @"请输入信息";
textView.textColor = [UIColor grayColor];
}
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
if([textView.text isEqualToString:@"请输入信息"]){
textView.text=@"";
textView.textColor=[UIColor blackColor];
}
}