码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发从入门到精通--XIB使用,登陆界面小试牛刀

时间:2016-07-31 15:58:35      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

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

iOS开发从入门到精通--XIB使用,登陆界面小试牛刀

标签:

原文地址:http://blog.csdn.net/android_it/article/details/52078705

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!