TextFieldDelegate

#import "AppDelegate.h"

@interface AppDelegate ()<UITextFieldDelegate>

@end

@implementation AppDelegate

/*

回收键盘的步骤
 1、遵守UITextFieldDelegate协议
 2、创建UITextField对象
 3、设置UITextField对象的delegate属性为AppDelegate
 4、实现UITextFieldDelegate的textFieldShouldReturn:方法
 5、在textFieldShouldReturn:方法取消textField作为第一响应者
 */

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //创建一个UIWindow对象
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    //创建一个UITextField对象
    UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 30)];
    text.backgroundColor = [UIColor redColor];
    [self.window addSubview:text];
    text.delegate = self;
    return YES;
}
//实现textFieldDelegate的textFieldShouldReturn:方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

时间: 2024-08-04 10:12:57

TextFieldDelegate的相关文章

利用TextFieldDelegate代理方法 – textField:shouldChangeCharactersInRange:replacementString: 限制输入字符

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField == _workIdTxt) { NSUInteger lengthOfString = string.length; for (NSInteger loopIndex = 0; loopIndex < lengthO

iOS 键盘处理(改变键盘为完成键),UITextField键盘显示隐藏,弹出,回弹

很多时候用到UITextField时,处理键盘是一个很棘手的问题. 问题一:如何隐藏键盘? 方案1.改变键盘右下角的换行(enter)键为完成键,后实现代理方法键盘自动回弹 keyBoardControll.gif UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 300, 200, 40)]; [self.view addSubview:textField]; textField.delegat

cocos2dx3.6 实现带光标的输入框

多的不说,我这个学渣,我写的代码比较搓!忍耐下吧! CursorTextField.h #ifndef _CursorTextField_H_ #define _CursorTextField_H_ #include "cocos2d.h" USING_NS_CC; class CursorTextField : public TextFieldTTF, public TextFieldDelegate , public IMEDelegate { private: // 点击开始位置

UITextFiled限制输入字符的数量

使用TextFieldDelegate中的方法: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacement

iOS第三方键盘高度获取不准确问题

直接上代码,搜狗的输入法 - (void)keyboardWasShown:(NSNotification*)aNotification { //一旦键盘遮挡了输入框,那么就抬起来 NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; if (CGRectGetMaxY(self.tex

笔记(实习第一周)

bounds的原点是(0,0),frame原点任意 bounds指再本身坐标系统的位置 frame是父坐标 UITextField的重绘 – textRectForBounds:    //重写来重置文字区域 – drawTextInRect:        //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了. – placeholderRectForBounds: //重写来重置占位符区域 – drawPlaceholderInRec

【iOS开发-65】QQ聊天界面案例:自定义cell、图片拉伸处理、NSNotification通知、键盘与视图移动以及输入框左边缩进处理

(1)案例 (2)源代码于素材下载 http://pan.baidu.com/s/1bnpiBCz (3)总结 --还是代码封装.控制器.视图.模型分别独立.里面还有很多代码可以独立出来整一个类. --如果某一个值只有特定的几个数字,那么可以用枚举来定义,注意命名规范 typedef enum{ WPMessageTypeMe=0, WPMessageTypeOther=1 }WPMessageType; --依然是计算一段文字所占据的宽和高 CGSize textMaxSize=CGSizeM

IOS开发隐藏键盘的4种方法

IOS开发隐藏键盘的4种方法 开发的app中常会用到键盘输入完成后隐藏键盘的情况.在此总结了4种方法来实现我们的目的. 方法一--delegate方式 第一种隐藏键盘的方法,称为delegate三步法: 1. 遵循(委托/代理); 2. 调用; 3. 关联头文件(ViewController.h)中遵循代理 . 代码如下: #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITextFieldDel

UITextField点击return后注销第一响应者

// 当点击了return按钮,就让text调用自己的endEditing方法 [textField addTarget:textField action:@selector(endEditing:) forControlEvents:UIControlEventEditingDidEndOnExit]; #pragma mark - textFieldDelegate // 结束编辑就让textField注销第一响应者 - (void)textFieldDidEndEditing:(UITex