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

- (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;

相关文章
相关标签/搜索