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

UITextView添加placeholder属性

2015-03-24 09:09 246 查看
1.先遵循UITextViewDelegate协议
2.设置全局变量textLable或者自定义一个UITextView,将lable设置为其属性
3.以下代码
#pragma mark -

#pragma mark 给UITextView添加placeholder

//
设置代理人

content.delegate =
self;

//
给UITextView添加标签

textLable = [[UILabel
alloc] initWithFrame:CGRectMake(10,
10,
300, 20)];

textLable.text =
@"请在此处输入正文";

textLable.enabled =
NO;

textLable.backgroundColor = [UIColor
clearColor];

[content
addSubview:textLable];
}

// 添加textView的方法
- (void)textViewDidChange:(UITextView *)textView
{

// NSLog(@"输出啦啦啦");

if (content.text.length ==
0) {

textLable.text =
@"请在此处输入正文";
}
else {

textLable.text =
@"";
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: