带提示(hint)的多行文本输入--UITextView

- (void) viewDidLoad {

    //...

    comments.text = @"请输入:";

    comments.textColor = [UIColor lightGrayColor];

    isEmpty = YES;

    //...

}

- (BOOL)textViewShouldBeginEditing:(UITextView*)textView {

    if (isEmpty) {

        comments.text = @"";

        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;



你可能感兴趣的:(带提示(hint)的多行文本输入--UITextView)