UITextView设置类似placeholder的效果
来源:互联网 发布:汇成凯网络 编辑:程序博客网 时间:2024/05/22 16:53
想要实现类似UITextFiled的placeholder的效果有如下两种方式,代码实现方式如下:
一、方法一:
- (void)viewDidLoad{ commentTxtView.text = @"Comment"; commentTxtView.textColor = [UIColor lightGrayColor]; commentTxtView.delegate = self;}- (BOOL) textViewShouldBeginEditing:(UITextView *)textView{ commentTxtView.text = @""; commentTxtView.textColor = [UIColor blackColor]; return YES;}-(void) textViewDidChange:(UITextView *)textView{ if(commentTxtView.text.length == 0){ commentTxtView.textColor = [UIColor lightGrayColor]; commentTxtView.text = @"Comment"; [commentTxtView resignFirstResponder]; }}
二、方法二:在textView中设置相关的UILable
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0,textView.frame.size.width - 10.0, 34.0)];[lbl setText:kDescriptionPlaceholder];[lbl setBackgroundColor:[UIColor clearColor]];[lbl setTextColor:[UIColor lightGrayColor]];textView.delegate = self;[textView addSubview:lbl];- (void)textViewDidEndEditing:(UITextView *)theTextView{ if (![textView hasText]) { lbl.hidden = NO;}}- (void) textViewDidChange:(UITextView *)textView{ if(![textView hasText]) { lbl.hidden = NO; }else{ lbl.hidden = YES; } }
如此简单,就是这么任性,亲,你会了吗???
1 0
- UITextView设置类似placeholder的效果
- 关于iOS UITextView的一点使用心得,设置placeHolder效果
- 实现UITextView的placeholder效果
- UITextView设置placeholder的方法
- iOS-UITextView设置行间距,内容颜色(变相设置类似UITextField的placeholder)
- ios UITextView placeHolder效果
- ios UITextView的placeHolder的设置
- iOS开发:设置UITextView的placeholder
- UITextView placeholder 设置
- UITextView 的placeholder
- UITextView 的placeholder
- UITextView的placeholder属性
- UITextView的placeholder属性
- UITextView的placeholder
- 给UITextView添加类似placeholder功能
- 针对UITextView设置placeHolder解析
- UITextView加上placeholder效果用UILabel
- UITextView的placeholder猥琐做法
- module_param_array
- swift2.0
- 华为OJ——IP地址判断有效性
- 《Java程序设计》第16周周四:GUI编程及文件对话框的使用
- 《转》openstack中删除虚拟主机,状态一直deleting
- UITextView设置类似placeholder的效果
- 《Java程序设计》第16周周四:GUI编程及文件对话框的使用
- java.lang.RuntimeException: Camera is being used after Camera.release() was called
- innodb_thread_concurrency 和 innodb_concurrency_tickets
- Eclipse (indigo) 中安装jdk包并运行Maven
- [JS]定时执行的处理类PeriodicalExecuter 介绍(可以替代setInterval)
- 进程的通信
- iOS_开发中遇到的那些问题_1
- effective C++中条款37:绝不重新定义继承而来的缺省参数值