IOS里面只有UITextField才有提示文字显示,而UITextView却没有,那如果有类似的需求我们怎么做呢,我们可以通过一种投机取巧的方式来实现这种需求
1.实现UITextViewDelegate中的textViewDidChange:方法:
- (void)textViewDidChange:(UITextView *)textView {
NSString *string = textView.text;
if(_inputHint && _inputHint.length > 2) {
_textView.text = [string substringWithRange:NSMakeRange(_inputHint.length, string.length-_inputHint.length)];
_textView.textColor = [UIColor blackColor]; //在这里改变字体颜色为你需要的颜色
_inputHint = nil;
}
}
2. 设置UITextView的代理为self
self.textView.delegate = self;
_inputHint = _textView.text = [NSString stringWithFormat:@"回复%d楼", (int)indexPath.row+1]; //Hint String
_textView.textColor = [UIColor lightGrayColor]; //HintText Color
[_textView becomeFirstResponder];
效果: