IOS开发学习笔记六 实现一个简单的登陆界面
程序员文章站
2022-04-11 13:54:15
...
首先是要实现的效果图:demo下载
首先在界面拖拽两个Label,分别命名为姓名和密码;
添加一个txtAccount,Text控件的placeholder类似于Android的Hint一样,这里设置为“请输入账号”,clearButton设置之后右侧会出现一个X号来进行输入信息的清楚,keyboard Type的类型设置为number pad,这样控件只允许输入数字:
再添加一个txtPsd,设置placeholder为“请输入密码”,然后设置clearButton为is always visible,设置keyboard Type的类型设置为ASCII Capable,这样控件允许输入字母和数字:
最后我们再分别为txtAccount和txtPsd添加对应的对象,并为登陆按钮添加btnLogin点击事件,具体代码如下:
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtAccount;
@property (weak, nonatomic) IBOutlet UITextField *txtPsd;
- (IBAction)btnLogin;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnLogin {
NSString * account = self.txtAccount.text;
NSString * psd = self.txtPsd.text;
NSLog(@"QQ账号:%@;QQ密码:%@",account,psd);
if([account isEqual:@"123456"] && [psd isEqual:@"123456"]){
NSLog(@"登陆成功");
}else{
NSLog(@"登陆失败");
}
[self.view endEditing:YES];
}
@end