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的软件简介.内容详情显示.小说阅 ...
随机推荐
- Jump
hdu4862:http://acm.hdu.edu.cn/showproblem.php?pid=4862 题意:给你n*m的方格,每个方格中有一个数(0---9),然后你每次可以选择一个点开始,这 ...
- Frame Stacking
poj1128:http://poj.org/problem?id=1128 题意:一个二维图里面有几个相框(四条边的空心矩形框).有重叠,求重叠顺序.还有题目保证至少存在一种符合要求的序列,当有多种 ...
- hdu 5147 Sequence II
http://acm.hdu.edu.cn/showproblem.php?pid=5147 题意:问有多少个这样的四元组(a,b,c,d),满足条件是 1<=a<b<c<d; ...
- 通过PHP连接MYSQL数据库 创建数据库 创建表
通过PHP连接MYSQL数据库 $conn = mysql_connect("localhost","root","password") ...
- swiper 多个循环的实现
swiper 最好要一一对应,最好与id关联. new Swiper('#guess .swiper-container', { pagination: '#guess .swiper-paginat ...
- 字符串(后缀自动机):Codeforces Round #129 (Div. 1) E.Little Elephant and Strings
E. Little Elephant and Strings time limit per test 3 seconds memory limit per test 256 megabytes inp ...
- 数据结构(括号序列,线段树||点分治,堆):ZJOI 2007 捉迷藏
[题目描述] Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩捉迷藏游戏.他们的家很大且构造很奇特,由N个屋子和N-1条双向走廊组成,这N- ...
- AC自动机(Aho-Corasick automation)模板 HDU:2222
#include <iostream> #include <cstdio> #include <cstring> #include <queue> us ...
- ACM第六周竞赛题目——B CodeForces 478B
B - B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Reward(拓扑排序)
http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意: 老板要给n个员工发工资最低工资是888: 但是工人们是有要求的 如果输入 a b 表示a的工资要比 ...