标签:
XIB使用,登陆界面小试牛刀
创建一个新的视图控制器,具体操作参见点击查看
在创建好的VCRoot.xib里面拖动需要的控件,并拖动给相应的控件添加属性,给登陆按钮添加事件。
VCRoot.h文件里面:
#import <UIKit/UIKit.h>
@interface VCRoot : UIViewController
//IBOutlet表示从xib中创建的
@property (weak, nonatomic) IBOutlet UITextField *mName;
@property (weak, nonatomic) IBOutlet UITextField *mPassword;
@property (weak, nonatomic) IBOutlet UIButton *mLogin;
//以上@property都是设置的属性
//下面这个是函数事件
- (IBAction)pressLogin:(id)sender;
@end
VCRoot.m文件里面:
#import "VCRoot.h"
@interface VCRoot ()
@end
@implementation VCRoot
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)pressLogin:(id)sender {
NSString * name = @"jack";
NSString * pass = @"123456";
//判断是否正确,并弹出对话框提示
if([_mName.text isEqual:name] && [_mPassword.text isEqual:pass]){
UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名和密码正确,登陆成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alert show];
}else{
UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名和密码不正确,请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alert show];
}
}
//点击空白处,收回键盘
-(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[_mName resignFirstResponder];
[_mPassword resignFirstResponder];
}
@end
标签:
原文地址:http://blog.csdn.net/android_it/article/details/52078705