iOS开发:设置UITextView的placeholder
2016-02-17 15:15
429 查看
在textView上添加placeholder,思路是在要编辑的UITextView底部再放一个UITextView,并且将前面的背景色设为透明,代码如下:
_placeholder = [[UITextView alloc] initWithFrame:self.frame]; [_placeholder setEditable:NO]; _placeholder.text = @"请输入..."; [self addSubview:_placeholder]; UITextView *textView = [[UITextView alloc] initWithFrame:self.frame]; textView.layer.cornerRadius = 10; textView.layer.borderColor = [[UIColor grayColor] CGColor]; textView.layer.borderWidth = 1; textView.backgroundColor = [UIColor clearColor]; [self addSubview:textView]; textView.delegate = self;
- (void)textViewDidChange:(UITextView *)textView { if ([textView.text isEqualToString:@""]) { _placeholder.hidden = NO; } else { _placeholder.hidden = YES; } }
相关文章推荐
- 分治法(divide & conquer algorithm)的理解
- invalidate()与postInvalidate()
- UIImagePickerController全面使用详解
- ios UIColor 自定义颜色
- 消息队列(Message Queue)基本概念
- Easyui下关于propertygrid中的批量check
- 获取UITableView指定行在指定视图中的位置
- spoj1182Sorted bit squence【数位dp】
- UITableViewCell左右侧滑动出现多个按钮
- CoreBluetooth - 中心模式
- UITableViewCell分割线左侧不能到达边缘的解决方案
- iOSUIBezierPath
- UIImagePickerController使用小结
- UIView的bounds和frame学习
- error :Java.exe finished with non-zero exit value 1(或2)
- 关于FineUI使用问题的一点记录。
- FrexibleSearch Query语法
- IOS中Key-Value Coding (KVC)的使用具体解释
- onInterceptTouchEvent dispatchTouchEvent requestDisallowInterceptTouchEvent
- UINavgationController