Ocelots_IOS开发笔记(1)- 登录界面

先看下整体的效果图:
[img]http://dl.iteye.com/upload/attachment/0076/9187/9a0811ef-2467-3d39-b80e-c7d257523ad7.png[/img]

[img]http://dl.iteye.com/upload/attachment/0076/9189/95b57e57-838a-3475-b7f8-656d24d7996f.png[/img]

主要涉及的功能点有:
1、密码输入框要隐藏输入字符,以黑点代替
2、Login时会检查输入框,若输入不合法,弹窗提示用户
3、Reset会清空输入
4、点击界面空白地方的时候,能够收起输入键盘,防止挡住用户点击登陆。

实现代码:

1、对于要隐藏输入的文本框,我们只需要把其secureTextEntry的属性设置为TRUE就行了:
self.password.secureTextEntry=TRUE;


2、Login功能会把用户输入保存到AppDelegate中,这样以后程序中需要的时候还可以取到:
-(IBAction)login:(id)sender{
NSString *userName = [self.userName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *password = [self.password.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if(userName.length==0||password.length==0){
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"Input invalid" message:@"UserName or Password is empty" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
}

[delegate.userState setObject:userName forKey:@"KUserName"];
[delegate.userState setObject:password forKey:@"KPassword"];

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = appDelegate.tabBar;

}


3、在Reset时,除了清空UI控件中的内容,还需要清空AppDelegate中的内容:
-(IBAction)reset:(id)sender{
self.userName.text=@"";
self.password.text=@"";
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.userState setObject:@"" forKey:@"KUserName"];
[delegate.userState setObject:@"" forKey:@"KPassword"];
}

注:所有与UI空间绑定的方法都需要返回类型IBAction

4、实现隐藏键盘的原理就是通过调用输入框控件的resignFirstResponder,意思是放弃自己的第一响应者的身份,这样,键盘就会自动消失了。实现的时候,我们需要为界面绑定方法,在界面有touchDown事件发生的时候,调用backgroundTap方法:
-(IBAction)backgroundTap:(id)sender
{
NSLog(@"%@",@"touch screen");
[self.userName resignFirstResponder];
[self.password resignFirstResponder];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值