学习笔记——textView的placeHolder简单设定

来源:互联网 发布:男士冬季护肤 知乎 编辑:程序博客网 时间:2024/05/04 19:58

从stackoverflow找到的一个非常不错的textView的placeholder设定,不需要自定义直接设定


核心代码  :

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{    if ([[textView text] isEqualToString:PLACE_HOLDER_TEXT]) {//PLACE_HOLDER_TEXT是一个nsstring的宏          textView.text = @"";          textView.textColor = [UIColor blackColor];    }    return YES;}-(BOOL)textViewShouldEndEditing:(UITextView *)textView{    if ([[textView text] length] == 0) {        textView.text = PLACE_HOLDER_TEXT;        textView.textColor = [UIColor lightGrayColor];    }    return YES;}


说明:



0 0