Storyboard学习五(简单注册页面实现)
2016-05-16 14:29
405 查看
主要功能点:
1. textField关联键盘
2. 用户名和密码的限制和过滤
3. 键盘收回操作
Check on the code
1. textField关联键盘
2. 用户名和密码的限制和过滤
3. 键盘收回操作
Check on the code
#import "ViewController.h" @interface ViewController() @end @implementation ViewController -(void)viewDidLoad{ [super viewDidLoad]; UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 90, 20)]; label1.font = [UIFont systemFontOfSize:15]; label1.text = @"用 户 名:"; label1.backgroundColor = [UIColor clearColor]; label1.textAlignment = NSTextAlignmentLeft; label1.numberOfLines = 2;//用于设置label中文本的行数 [self.view addSubview:label1]; UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 90, 90, 20)]; label2.font = [UIFont systemFontOfSize:15]; label2.text = @"密 码:"; label2.backgroundColor = [UIColor clearColor]; label2.textAlignment = NSTextAlignmentLeft; [self.view addSubview:label2]; UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, 130, 90, 20)]; label3.font = [UIFont systemFontOfSize:15]; label3.text = @"确认密码:"; label3.backgroundColor = [UIColor whiteColor]; label3.textAlignment = NSTextAlignmentLeft; [self.view addSubview:label3]; UITextField *textField1 = [[UITextField alloc]initWithFrame:CGRectMake(110, 50, 200, 20)]; textField1.backgroundColor = [UIColor clearColor]; textField1.placeholder = @"请输入用户名"; textField1.tag = 1; [textField1 setSecureTextEntry:NO]; textField1.font = [UIFont systemFontOfSize:14]; //textField1.delegate = self; textField1.autocapitalizationType = UITextAutocapitalizationTypeNone;//否则默认首字母大写 textField1.borderStyle = UITextBorderStyleRoundedRect; [self.view addSubview:textField1]; UITextField *psField1 = [[UITextField alloc]initWithFrame:CGRectMake(110, 90, 200, 20)]; psField1.backgroundColor = [UIColor clearColor]; psField1.placeholder = @"至少6位字母或数字"; psField1.tag = 2; psField1.font = [UIFont systemFontOfSize:14]; //psField1.delegate = self; psField1.borderStyle = UITextBorderStyleRoundedRect; psField1.keyboardType = UIKeyboardTypeDefault; psField1.keyboardAppearance = UIKeyboardAppearanceDark; [psField1 setSecureTextEntry:YES]; [self.view addSubview:psField1]; UITextField *psField2 = [[UITextField alloc]initWithFrame:CGRectMake(110, 130, 200, 20)]; psField2.backgroundColor = [UIColor clearColor]; psField2.font = [UIFont systemFontOfSize:14]; psField2.borderStyle = UITextBorderStyleRoundedRect; psField2.placeholder = @"请再次输入密码"; psField2.tag = 3; psField2.keyboardType = UIKeyboardTypeDefault; psField2.keyboardAppearance = UIKeyboardAppearanceDark; [psField2 setSecureTextEntry:YES]; [self.view addSubview:psField2]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setFrame:CGRectMake(110, 170, 180, 30)]; [btn setTitle:@"提交" forState:UIControlStateNormal];//正常状态下button显示的标题 [btn setTitle:@"提交" forState:UIControlStateHighlighted];//高亮显示时button的标题 btn.backgroundColor = [UIColor greenColor]; //button被按下又抬起后发生的事件 [btn addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside]; //selector可以理解为一个选择子,是指针变量,类似于sender。这里是将这个方法指定给新建的这个button [self.view addSubview:btn]; } //收回键盘 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { for (int i =0; i < 4; i++) { UITextField *textField = (UITextField *)[self.view viewWithTag:1+i]; [textField resignFirstResponder]; } } }
相关文章推荐
- 01背包专题
- BestCoder Round #83 1001&&HDU-5680 zxa and set (水)
- springmvc + hibernate + mysql + maven 简单应用
- QT-Demo-Colck-01
- Bootstrap4一次重大更新 几乎涉及每行代码
- HTTP 消息结构
- mac升级到10.11后使用CocoaPod出现-bash: pod: command not found 解决办法
- C++第10/11周项目 继承与派生 【项目4- 教师兼干部类】(复习新版)
- WCF NetTcpBinding.ReaderQuotas.MaxDepth 引用异常故障排除
- 02 Struts2开发环境的搭建和第一个Struts2应用开发
- inline 内联函数的使用
- [算法][C]计算向量的角度
- 通讯录的实现(二)动态实现
- 夜半对话
- 线性表的操作 (2.2) C = A U B
- android应用换肤功能的实现
- RT3070 网卡移植
- ASP.NET的视图(Razor)循环产生html代码
- UI自动化
- JS图片延迟加载分析及简单的demo