#pragma mark -- UITextFieldDelegate协议函数 标记 快速定位
#warning xxxxxx 警告
********
建立代理:
1.分清委托者和代理者
2.委托者中写协议(类名+delegate)
3.委托者中写代理属性
4.委托者制定协议方法(分清是否需要带参)
5.代理调用协议方法(需要判断代理是否能够相应协议函数)
6.代理者遵守协议
7.建立代理
8.代理者写协议中的方法
注意:
调用一次
- (void)loadView
调用一次
- (void)viewDidLoad
顺序:
secondVC.name = @"jianhao";
secondVC.view.backgroundColor = [UIColor yellowColor];
一些概念:
1.UITextField是文本输入框,它的特点是输入的内容不能换行
UITextField *testField = [[UITextField alloc] initWithFrame:CGRectMake(40, 100, 300, 40)];
2.设置文本输入框的样式
testField.borderStyle = UITextBorderStyleLine;
3.设置背景图片 前提条件是文本输入框的样式不能设置为
UITextBorderStyleRoundRect 否则背景图片不能显示
testField.background = [UIImage imageNamed:@"angry_00.jpg"];
4.提示文字
testField.placeholder = @"迅捷斥候";
5.设置预填文字
testField.text = @"加速";
6.当文本输入框开始编辑时,删除文本框中的文字,默认为NO
testField.clearsOnBeginEditing = YES;
/*
UITextFieldViewModeNever, 默认 永不显示
UITextFieldViewModeWhileEditing, 当开始编辑的时候显示
UITextFieldViewModeUnlessEditing, 没有在编辑状态的情况下显示
UITextFieldViewModeAlways 永远显示
*/
7.设置删除按钮显示的时机
testField.clearButtonMode = UITextFieldViewModeAlways;
8.设置文本输入框左侧视图
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
imageView.image = [UIImage imageNamed:@"player1"];
9.以下两个属性是配对使用
testField.leftView = imageView;
testField.leftViewMode = UITextFieldViewModeAlways;
10.文本是否以密文显示 YES 以密文显示 默认为NO
testField.secureTextEntry = YES;
11.设置键盘样式
testField.keyboardType = UIKeyboardTypeDefault;
12.设置return键样式
testField.returnKeyType = UIReturnKeyDone;
在这个地方设置 x y width 没有作用
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 50)];
13.建立代理关系
testField.delegate = self;
14.成为第一响应者(不用点击,键盘自动出来)
[testField becomeFirstResponder];
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// UITextField *textF = (UITextField *)[self.view viewWithTag:100];
//注销掉第一相应者(点空白地方键盘自动收回)
// [textF resignFirstResponder];
//关闭键盘
[self.view endEditing:YES];
NSLog(@"我被点击了");
}
15.设置动画效果
secondVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;