UITextView和UITextField的placeholder,键盘隐藏,键盘换行变完成字样
本文转载至
{
//设置页面的背景颜色
UIColor *ViewBgColor = [UIColor colorWithRed:(247.0f/255.0f)green:(247.0f/255.0f) blue:(247.0f/255.0f) alpha:1.0f];
self.view.backgroundColor = ViewBgColor;
UILabel *fix_feed_label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 70, 30)];
fix_feed_label.text = @"意见内容";
fix_feed_label.backgroundColor = [UIColor clearColor];
fix_feed_label.textColor = [UIColor blackColor];
_content_textView = [[UITextView alloc]initWithFrame:CGRectMake(10, 25, 300, 80)];
_content_textView.font = [UIFont boldSystemFontOfSize:13];
_content_textView.delegate = self;
//设置键盘,使换行变为完成字样
_content_textView.keyboardType = UIKeyboardAppearanceDefault;
_content_textView.returnKeyType = UIReturnKeyDone;
_placeholder_label = [[UILabel alloc]initWithFrame:CGRectMake(12, 25, 300, 30)];
_placeholder_label.text = @"请留下您的宝贵意见或建议(不少于10个汉字)";
_placeholder_label.font = [UIFont boldSystemFontOfSize:13];
_placeholder_label.textColor = [UIColor lightGrayColor];
_placeholder_label.layer.cornerRadius = 10;
_placeholder_label.layer.masksToBounds = YES;
UILabel *fix_contact_label = [[UILabel alloc]initWithFrame:CGRectMake(10, 105, 160, 30)];
fix_contact_label.text = @"联系方式 (选填)";
fix_contact_label.backgroundColor = [UIColor clearColor];
fix_contact_label.textColor = [UIColor blackColor];
_contact_field = [[UITextField alloc]initWithFrame:CGRectMake(15, 130, 300, 30)];
[_contact_field setBorderStyle:UITextBorderStyleNone];
_contact_field.font = [UIFont boldSystemFontOfSize:13];
_contact_field.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
_contact_field.keyboardType = UIKeyboardAppearanceDefault;
_contact_field.returnKeyType = UIReturnKeyDone;
_contact_field.placeholder = @"手机号码或EMAIL";
_contact_field.delegate = self;
_submit_button = [UIButtonbuttonWithType:UIButtonTypeCustom];
[_submit_button setFrame: CGRectMake(0, 0, 55, 27)];
UIColor *sequenceColor = [UIColor colorWithRed:(246.0f/255)green:(109.0f/255.0f) blue:(9.0f/255.0f) alpha:1.0f];
_submit_button.backgroundColor = sequenceColor;
[_submit_button setTitle:@"提交"forState:UIControlStateNormal];
[_submit_button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
[_submit_button addTarget:self action:@selector(clickSubmit:)forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:_submit_button];
[self.view addSubview:fix_feed_label];
[self.view addSubview:fix_contact_label];
[self.view addSubview:_content_textView];
[self.view addSubview:_placeholder_label];
[self.view addSubview:_contact_field];
}
- (void)clickSubmit:(id)sender
{
NSLog(@"clickSubmit");
}
/*
基于UIView点击编辑框以外的虚拟键盘收起
**/
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (![self.content_textView isExclusiveTouch]||(![self.contact_field isExclusiveTouch])) {
if (self.content_textView.text.length == 0)
{
NSLog(@"ssssss");
self.placeholder_label.text = @"请留下您的宝贵意见或建议(不少于10个汉字)";
_placeholder_label.hidden = NO;
}
[self.content_textView resignFirstResponder];
[self.contact_field resignFirstResponder];
}
}
/*
键盘收回事件,UITextField协议方法
**/
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return NO;
}
#pragma textViewDelegate
-(void)textViewDidChange:(UITextView *)textView
{
if (self.content_textView.text.length != 0) {
self.placeholder_label.text = @"";
_placeholder_label.hidden = YES;
}
else{
self.placeholder_label.text = @"请留下您的宝贵意见或建议(不少于10个汉字)";
_placeholder_label.hidden = NO;
}
}
- (void)textViewDidBeginEditing:(UITextView *)textView;
{
self.placeholder_label.text = @"";
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([@"\n" isEqualToString:text] == YES)
{
[textView resignFirstResponder];
if (self.content_textView.text.length == 0)
{
NSLog(@"ssssss");
self.placeholder_label.text = @"请留下您的宝贵意见或建议(不少于10个汉字)";
_placeholder_label.hidden = NO;
}
return NO;
}
return YES;
}
UITextView和UITextField的placeholder,键盘隐藏,键盘换行变完成字样的更多相关文章
- 用UITextView模拟UITextField的placeHolder
用UITextView模拟UITextField的placeHolder 效果: 源码: // // ViewController.m // TextView // // Created by You ...
- UITextView模拟UITextField 设置Placeholder属性 --董鑫
由于最近有用到输入框,刚开始考虑的是UITextField,因为它在没有输入的时候可以有提示的Placeholder更能,很人性化,但UITextField只能单行输入,不能跳行,对于一些强迫症的亲来 ...
- UITextView 点return 隐藏键盘
iOS开发中,发现UITextView没有想UITextField中textFieldShouldReturn:这样的方法,那么要实现UITextView return键隐藏键盘,可以通过判断输入的字 ...
- iOS-UITextField和UITextView隐藏键盘
UITextField和UITextView隐藏键盘 71 views, IOS DEV, by admin. self._textField.returnKeyType=UIReturnKeyDon ...
- 【转】iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
iOS上面对键盘的处理很不人性化,所以这些功能都需要自己来实现, 首先是点击return和屏幕隐藏键盘 这个首先引用双子座的博客 http://my.oschina.net/plumsoft/blog ...
- IOS中键盘隐藏几种方式
在ios开发中,经常需要输入信息.输入信息有两种方式: UITextField和UITextView.信息输入完成后,需要隐藏键盘,下面为大家介绍几种隐藏键盘的方式. <一> 点击键盘上的 ...
- 隐藏键盘的N种方法
---Created by luo.h 显示键盘 [textField becomeFirstResponder]; 隐藏键盘 @interface ViewController ()<UITe ...
- ios隐藏键盘
1.点击页面空白处隐藏键盘 给viewController里面复写-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法,在 ...
- QF——UI之几种常用的隐藏键盘的方法
怎么在填写完UITextField之后,点击空白处,隐藏软键盘. 下面两个方法都可以隐藏键盘 [tf resignFirstResponder]; 停止textfield的第一响应者 [self.vi ...
随机推荐
- 【C#/WPF】获取项目的根目录(Root Directory)
/// <summary> /// 获得项目的根路径 /// </summary> /// <returns></returns> public str ...
- u-boot 2016.05 添加u-boot cmd
记录一下如何在u-boot 添加一个自己想要的命令. 首先来看一下宏,include/command.h 218 #define U_BOOT_CMD(_name, _maxargs, _rep, _ ...
- 奇妙的go语言(面向对象)
[ 声明:版权全部.欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 有过C++语言学习经历的朋友都知道.面向对象主要包含了三个基本特征:封装.继承和多态.封装,就 ...
- Cocos2d-x 3.0final 终结者系列教程06-Director和场景跳转
这些天互联网大事不少呀 1.逻辑思维分家(所谓合久必分,分久必合,实属正常.切行切珍惜吧) 2. 锤子手机开卖 (无论你买没买,反正我没买,作为多年Android开发的我深知说的亮点事实上在我看来都 ...
- kill 信号大全
linux kill信号列表$ kill -l1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL5) SIGTRAP 6) S ...
- 可变长度子网掩码(VLSM)在子网划分中的应用
在学习可变长度子网掩码时,必须先熟练掌握二进制与十进制的转化.计算机中数据的单位(字节.位)等知识. 一.什么是可变长度子网掩码? 要理解可变长度子网掩码,先要理解子网掩码:要理解子网掩码,先要理解I ...
- Java中Calendar.DAY_OF_WEEK需要减一的原因
http://blog.sina.com.cn/s/blog_45c06e600100pm77.html ——————————————————————————————————————————————— ...
- html测试代码框工具
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --& ...
- 获取FirefoxProfile配置文件以及使用方法介绍
使用默认方式构建的(WebDriver)FirefoxDriver实例: WebDriver driver = new FirefoxDriver(); 这种方式下,打开的Firefox浏览器将是不带 ...
- javax.naming.NoInitialContextException错误的解决方案
今天,学习用了一下nutz框架,写了一个HelloWorld的小程序,在用jndi配置数据源时,写了一个测试类,并在main方法中调用了jndi获得数据库连接,但是报错了,错误信息如下: javax. ...