标签:
平时开发中老是出现多行的文本而且要有placeholder提示,就自己整理项目中部分代码以供参考、讨论,希望有更好实现方法的人多多指教。
思路:通过改变UITextView的文本颜色实现placeholder效果,通过改变UITableView的setContentOffset方法解决键盘遮挡
1、创建UITextView
textView = [[UITextViewalloc] init];
textView.font = [UIFontsystemFontOfSize:14];
textView.frame =CGRectMake(10, 0,DEVICE_WIDTH-20,56);
textView.autoresizingMask =UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth;
textView.backgroundColor = [UIColorclearColor];
textView.textColor=[UIColorcolorWithHexString:@"#999999"];
textView.delegate =self;
textView.text=@"请在这里输入";
[self.view addSubview:textView];
2、UITextView delegate-
#pragma mark -----UITextView delegate-----
//开始编辑
-(void)textViewDidBeginEditing:(UITextView *)textView
{
[tableviewsetContentOffset:CGPointMake(0,100) animated:YES];
if ([textView.textisEqualToString:@"请在这里输入"]) {
textView.textColor=[UIColorcolorWithHexString:@"#77FF00"];
textView.text =@"";
}
}
//完成编辑
-(void)textViewDidEndEditing:(UITextView *)textView
{
if (textView.text.length==0||[textView.textisEqualToString:@""]) {
textView.textColor=[UIColorcolorWithHexString:@"#999999"];
textView.text=@"请在这里输入";
}
else
{
detailAddress.text= textView.text;
}
[tableviewsetContentOffset:CGPointMake(0, 0)animated:YES];
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
IOS控件UITextView 实现placeholder效果和解决UITableView键盘遮挡
标签:
原文地址:http://blog.csdn.net/niepeng109/article/details/46713473