您的位置:首页 > 产品设计 > UI/UE

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: