- (void) viewDidLoad {spa
//...code
comments.text = @"請輸入:";it
comments.textColor = [UIColor lightGrayColor];協議
isEmpty = YES;margin
//...di
}文件
- (BOOL)textViewShouldBeginEditing:(UITextView*)textView {view
if (isEmpty) {vi
comments.text = @"";co
comments.textColor = [UIColor blackColor];
isEmpty = NO;
}
return YES;
}
- (void) textViewDidEndEditing:(UITextView*)textView {
if(comments.text.length == 0){
comments.textColor = [UIColor lightGrayColor];
comments.text = @"請輸入:";
isEmpty = YES;
}
}
注意:須要在.h文件種添加協議<UITextViewDelegate>,在.m文件種設置協議 comments.delegate=self;