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的软件简介.内容详情显示.小说阅 ...
随机推荐
- Entity Framework OData filter inherit
过滤继承对象 TPH 的情况 EF : return Task.FromResult<IQueryable<Parent>>( query.OfType<ChildA&g ...
- Rabbit hunt
poj2606:http://poj.org/problem?id=2606 给你n个点,求在一条直线上的点最多有几个.题解:直接暴力,但是要注意,横坐标相等的情况,这是不能求斜力,只能特殊处理. # ...
- linux eclipse c++配置
安装cdt: https://www.eclipse.org/cdt/downloads.php 新建一个c++工程,运行发生错误: Eclipse CDT launch failed.Binary ...
- jQuery Validate 验证,校验规则写在控件中的具体例子
将校验规则写到控件中 <script src="../js/jquery.js" type="text/javascript"></scrip ...
- c语言小练习(蛮好玩的)
1.求三个数的平均数,要求保留三位小数位 #include <conio.h> #include<stdio.h> int main(){ int a,b,c; float a ...
- hdu-1890-Robotic Sort splay区间翻转
题意: 依次找第i大的数下标pos[i],然后将区间[i,pos[i]]翻转 分析: splay树区间翻转 // File Name: ACM/HDU/1890.cpp // Author: Zlbi ...
- 线性代数(矩阵乘法):POJ 2778 DNA Sequence
DNA Sequence Description It's well known that DNA Sequence is a sequence only contains A, C, T and ...
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- C++中delete和 delete[]的区别
总的原则是,如果是用new[]创建的,则用delete[]删除,如果是用new创建的,则用delete删除. 对于基本类型,比如char *p=new char[20];如果删除时,delete p和 ...
- [Locked] Shortest Word Distance I & II & III
Shortest Word Distance Given a list of words and two words word1 and word2, return the shortest dist ...