扫码关注官方订阅号
iOS 的textView有没有自带的设置提示文字的方法,我试过在上面加一个UILabel可以实现,但是觉得有点麻烦,求大神指教一下!
小伙看你根骨奇佳,潜力无限,来学PHP伐。
自己写个逻辑
// tips是提示文本 - (void)addTextView { UITextView *textView = [UITextView new]; textView.text = tips; textView.textColor = [UIColor grayColor]; _inputContent = @""; ………………省略 } - (void)textViewDidBeginEditing:(UITextView *)textView { if ([_inputContent isEqualToString:@""]) { textView.text = @""; textView.textColor = [UIColor blackColor]; } else { textView.textColor = [UIColor blackColor]; } } - (void)textViewDidEndEditing:(UITextView *)textView { if (textView.text && [textView.text length] > 0) { _inputContent = textView.text; textView.textColor = [UIColor blackColor]; } else { _inputContent = @""; textView.text = tips; textView.textColor = [UIColor grayColor]; } }
textView里显示的是表象,_inputContent相当于你的数据源
注意placeholder是自定义的添加到texView即可
- (void)paste:(id)sender { UIPasteboard *board = [UIPasteboard generalPasteboard]; self.textView.text = board.string; [self resignFirstResponder]; } -(void)keyboardHideClick:(UITapGestureRecognizer*)tap{ [self.textView resignFirstResponder]; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if (![text isEqualToString:@""]) { _placeholderLabel.hidden = YES; } if ([text isEqualToString:@""] && range.location == 0 && range.length == 1) { _placeholderLabel.hidden = NO; } return YES; }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
自己写个逻辑
textView里显示的是表象,_inputContent相当于你的数据源
注意placeholder是自定义的添加到texView即可