在UITextField中自带placeholder属性,可以用于提示输入框信息。但是UITextView并不具备此功能介绍一种方法来实现初始化UITextView:
//首先定义UITextView UITextView *textView = [[UITextView alloc] init]; textView.font = [UIFont systemFontOfSize:14]; textView.frame =CGRectMake(20, 66, self.view.frame.size.width, 120); textView.backgroundColor = [UIColor whiteColor]; [cell.contentView addSubview:textView];textView.delegate = self;//其次在UITextView上面覆盖个UILable,UILable设置为全局变量showLabel.frame =CGRectMake(25, 70,self.view.frame.size.width-50, 20); showLabel.text = @"这是提示文字..."; showLabel.enabled = NO;//lable必须设置为不可用 showLabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:showLabel];
//实现UITextView的代理-(void)textViewDidChange:(UITextView *)textView { if (textView.text.length == 0) { showLabel.text = @"这是提示文字..."; }else{ showLabel.text = @""; } } 内容仅供参考,欢迎大家提供更多的方法来交流
时间: 2024-11-04 18:39:06