本文转载至

http://blog.csdn.net/hengshujiyi/article/details/9086093- (void)initFeedBackViews

{

//设置页面的背景颜色

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,键盘隐藏,键盘换行变完成字样的更多相关文章

  1. 用UITextView模拟UITextField的placeHolder

    用UITextView模拟UITextField的placeHolder 效果: 源码: // // ViewController.m // TextView // // Created by You ...

  2. UITextView模拟UITextField 设置Placeholder属性 --董鑫

    由于最近有用到输入框,刚开始考虑的是UITextField,因为它在没有输入的时候可以有提示的Placeholder更能,很人性化,但UITextField只能单行输入,不能跳行,对于一些强迫症的亲来 ...

  3. UITextView 点return 隐藏键盘

    iOS开发中,发现UITextView没有想UITextField中textFieldShouldReturn:这样的方法,那么要实现UITextView return键隐藏键盘,可以通过判断输入的字 ...

  4. iOS-UITextField和UITextView隐藏键盘

    UITextField和UITextView隐藏键盘 71 views, IOS DEV, by admin. self._textField.returnKeyType=UIReturnKeyDon ...

  5. 【转】iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法

    iOS上面对键盘的处理很不人性化,所以这些功能都需要自己来实现, 首先是点击return和屏幕隐藏键盘 这个首先引用双子座的博客 http://my.oschina.net/plumsoft/blog ...

  6. IOS中键盘隐藏几种方式

    在ios开发中,经常需要输入信息.输入信息有两种方式: UITextField和UITextView.信息输入完成后,需要隐藏键盘,下面为大家介绍几种隐藏键盘的方式. <一> 点击键盘上的 ...

  7. 隐藏键盘的N种方法

    ---Created by luo.h 显示键盘 [textField becomeFirstResponder]; 隐藏键盘 @interface ViewController ()<UITe ...

  8. ios隐藏键盘

    1.点击页面空白处隐藏键盘 给viewController里面复写-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法,在 ...

  9. QF——UI之几种常用的隐藏键盘的方法

    怎么在填写完UITextField之后,点击空白处,隐藏软键盘. 下面两个方法都可以隐藏键盘 [tf resignFirstResponder]; 停止textfield的第一响应者 [self.vi ...

随机推荐

  1. 一款基于jquery的鼠标经过图片列表特效

    今天要给大家推荐一款基于jquery的鼠标经过图片列表特效.当鼠标经过列表图片的时候,图片放大,且有一个半透明的遮罩层随之移动.效果图如下: 在线预览   源码下载 实现的代码 html代码: < ...

  2. dubbox2.8.4例子教程一

    简介 Dubbo是一个来自阿里巴巴的开源分布式服务框架,当当根据自身的需求,为Dubbo实现了一些新的功能,包括REST风格远程调用.Kryo/FST序列化等等.并将其命名为Dubbox(即Dubbo ...

  3. window 服务(一)

    windows服务应用程序是一种长期运行在操作系统后台的程序,它对于服务器环境特别适合,它没有用户界面,不会产生任何可视输出,任何用户输出都回被写进windows事件日志.计算机启动时,服务会自动开始 ...

  4. 【Unity】UGUI无法修改字体大小

    无论怎么修改Font Size都无法调整字体大小? 如果勾选了Best FIt属性,那么字体大小将不受Font Size属性控制,且字体大小会调整为填满控件的矩形. 文档中对该属性的描述:

  5. [log]利用logrotate对Linux log进行管理

    转自:http://feikiss.iteye.com/blog/1402181 https://linux.cn/article-4126-1.html Syslog-ng服务是Linux系统中重要 ...

  6. 关于pthread_cond_wait使用while循环判断的理解

    在Stevens的<Unix 环境高级编程>中第11章线程关于pthread_cond_wait的介绍中有一个生产者-消费者的例子P311,在进入pthread_cond_wait前使用w ...

  7. 【Qt Tips】QLineEdit内容过滤之setValidator和setInputMask浅析

    1.QValidator分析 2.InputMask格式 3.测试代码和用例 项目路径: GitHub: https://github.com/Qunero/NeoQtTestDemo/tree/ma ...

  8. ftp 长传报错553 可能是选的目录不对

    ftp> put /root/20180711tmp.txt /cc.txt local: /root/20180711tmp.txt remote: /cc.txt 200 PORT comm ...

  9. node-webkit读取json文件

    1.原理 node-webkit包含了node.js,node.js提供了处理json数据文件的方法,通过node.js提供的方法,我们可以比较方便地读取json文件. 2.示例 这里我们读取的文件是 ...

  10. js学习笔记15----子节点和兄弟节点的操作

    1.元素.firstChild : 只读属性,第一个子节点 标准下:会包含文本类型的子节点. 非标准下:只包含元素类型子节点. 元素.firstElementChild : 只读属性,第一个元素子节点 ...