UITextView textViewShouldEndEditing
最近做到UITextView, 在取消键盘事件上我以为和UITextField差不多,于是我这样写:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(, , , )];
[textView setBackgroundColor:[UIColor greenColor]];
[textView setFont:[UIFont fontWithName:@"MyriadPro-Regular" size:]];
[textView setTextColor:[UIColor blackColor]];
[textView setText:@"Your Message...."];
[textView setBackgroundColor:[UIColor clearColor]];
[textView setDelegate:self];
[textView setReturnKeyType:UIReturnKeyDone];
我以为,当按下键盘上的“完成”按钮后,将被调用
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
NSLog(@"called");
[textView resignFirstResponder];
return YES;
}
然而我忘记了textView有换行的事件,即
点击Return
,它只是在textview里换行。所以,如果你想捕捉到换行\n
时取消响应resignFirstResponder
,可以这样
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ( [text isEqualToString:@"\n"] ) {
[textView resignFirstResponder];
}
return YES;
}
UITextView textViewShouldEndEditing的更多相关文章
- UITextView 点击添加文字 光标处于最后方
#import "ViewController.h" @interface ViewController ()<UITextViewDelegate> @end @im ...
- 你真的了解UITextView吗?
一:首先查看一下关于UITextView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextView : UIScrollView <UITextI ...
- UITextView的使用详解
//初始化并定义大小 UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 30)]; te ...
- iOS - UITextView
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextView : UIScrollView <UITextInput> @available(i ...
- iOS开发——UI篇Swift篇&UITextView
UITextView 一:UITextView使用及其属性的设置 titleLabel.text = titleString //创建UITextView对象 textView = UITextVie ...
- iOS - UI - UITextView
1.UITextView //因为继承于UIScrollView 拥有scrollView的所有属性和方法 //placeholder只有UITextField有,UITextView是没有的.(提示 ...
- UITextView -- 基础备忘
UITextView 这篇文章只涉及到基本的使用,日后会写一些关于结合TextKit的备忘 基本属性 let screenSize = UIScreen.mainScreen().bounds.siz ...
- 【转】UITextView的使用详解
//初始化并定义大小 UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 30)]; te ...
- UITextView(文本视图) 学习之初体验
UITextView文本视图相比与UITextField直观的区别就是UITextView可以输入多行文字并且可以滚动显示浏览全文.常见UITextView使用在APP的软件简介.内容详情显示.小说阅 ...
随机推荐
- [转]Aggregate tasks i Sharepoint 2013
from http://sharepoint247.com/mysite/aggregate-tasks-i-sharepoint-2013/ Aggregate tasks i Sharepoint ...
- Struts2 实现分页
1.转自:http://www.cnblogs.com/shiyangxt/archive/2008/11/04/1316737.html环境:MyEclipse6.5+Mysql5+struts2. ...
- Java类加载的时机
类是什么时候初始化的?类初始化的时候会执行static块,这个是我们知道的.那么我们可以用static块来做个实验. 上面代码输出是: hello worldinitthis is a test这说明 ...
- strtotime的几种用法区别
strtotime不仅可以使用类似Y-m-d此类标准的时间/日期字符串来转化时间戳, 还可以用类似自然语言的来生成时间戳, 类似: strtotime('last day'); strtotime(' ...
- 构造函数语义学之Default Constructor构建操作
一.Default Constructor的构建操作 首先大家要走出两个误区: 1).任何class如果没有定义default constructor,就会被合成一个来. 2).便以其合成出来的def ...
- Linux Kernel 本地拒绝服务漏洞
漏洞名称: Linux Kernel 本地拒绝服务漏洞 CNNVD编号: CNNVD-201308-090 发布时间: 2013-08-08 更新时间: 2013-08-08 危害等级: 漏洞类 ...
- 今天修改bug基本完成
今天修改bug基本完成 在修改bug过程中配到几个郁闷的问题,印象最深的两个1.检查出生日期或日期的合法性,引用的日历控件不能完全保证取到值时操作,现在突然想到或许我该仔细研究日历控件接口,在返回错误 ...
- Xmanager4使用记录
想在windows下远程登录到了Linux桌面,但又不想装vnc server,况且根据同学的实践,vnc的桌面在远程和本地都能看得到,这个似乎不太好. google到xmanager,装了个测试 ...
- (转载)php flush()刷新不能输出缓冲的原因分析
(转载)http://www.webkaka.com/tutorial/php/2012/110628/ 在php程序编写中,flush()的使用率还是挺高的,它在网页表现即时信息效果时发挥了极为重要 ...
- zoj 3462
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> ...