QQ登陆注册

#import "MainViewController.h"
#import "CustomView.h"
#import "PassViewController.h"
#import "RegistViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController
- (void)dealloc
{
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self creatView];
    [self CreatButton];
}

- (void)creatView
{

    CustomView *userName = [[CustomView alloc] initWithFrame:CGRectMake(30, 150, 280, 40) text:@"用户名"];
    [self.view addSubview:userName];
    userName.tag = 100;
    userName.leftText.tag = 1000;
    [userName release];

    CustomView *passWord = [[CustomView alloc] initWithFrame:CGRectMake(30, 200, 280, 40) text:@"密码"];
    [self.view addSubview:passWord];
    passWord.tag = 10;
    passWord.leftText.tag = 2000;
    passWord.leftText.secureTextEntry = YES;//密码模式
    [self.view release];


}
// 回收键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CustomView *pas = (CustomView *)[self.view viewWithTag:10];
    CustomView *name = (CustomView *)[self.view viewWithTag:100];
    [pas.leftText resignFirstResponder];
    [name.leftText resignFirstResponder];
}

- (void)CreatButton
{

    // 登录按钮
    UIButton * loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    loginButton.frame = CGRectMake(50, 260, 60, 40);
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loginButtonCLicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];


    // 找回密码按钮
    UIButton * foundButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [foundButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

    foundButton.frame = CGRectMake(150, 260, 80, 40);
    [foundButton setTitle:@"找回密码" forState:UIControlStateNormal];
    [foundButton addTarget:self action:@selector(foundButtonCLicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:foundButton];


    // 注册按钮
    UIButton * registButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [registButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

    registButton.frame = CGRectMake(260, 260, 60, 40);
    [registButton setTitle:@"注册" forState:UIControlStateNormal];
    [registButton addTarget:self action:@selector(registButtonCLicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registButton];



}

- (void)loginButtonCLicked:(id)sender
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:1000];
    UITextField * textField1 = (UITextField *)[self.view viewWithTag:2000];
    if ([textField.text isEqualToString:@""]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"傻逼" message:@"用户名不能为空" delegate:nil  cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
        [alertView show];
        [alertView release];
    }
    else if ([textField.text isEqualToString:@"yu"]) {
        if ([textField1.text isEqualToString:@"123"]) {

            UIAlertView *successView = [[UIAlertView alloc] initWithTitle:@"么么哒" message:@"您登录成功" delegate:self cancelButtonTitle:@"back" otherButtonTitles:nil, nil];
            [successView show];
            [successView release];
        }
        else if(![textField1.text isEqualToString:@"123"] && ![textField1.text isEqualToString:@""])
        {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"(☆_☆)" message:@"你确定密码对么?" delegate:nil  cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
            [alertView show];
            [alertView release];
        }

    }
    if([textField1.text isEqualToString:@""]){
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"(☆_☆)" message:@"请输入密码!!!" delegate:nil  cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
        [alertView show];
        [alertView release];
    }
    else if(![textField.text isEqualToString:@"yu"] && ![textField.text isEqualToString:@""] && ![textField1.text isEqualToString:@""])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您输入的用户不存在" delegate:nil  cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
        [alertView show];
        [alertView release];
    }

}

// 找回按钮action
- (void)foundButtonCLicked:(id)sender
{
    PassViewController *passVC = [[PassViewController alloc] init];
    [self presentViewController:passVC animated:YES completion:^{

    }];
    [passVC release];
}

// 注册按钮action
- (void)registButtonCLicked:(id)sender
{
    RegistViewController *registVC = [[RegistViewController alloc] init];

    [self presentViewController:registVC animated:YES completion:^{

    }];
    [registVC release];
}

## import "RegistViewController.h 页面##
#import "RegistViewController.h"
#import "CustomView.h"
@interface RegistViewController ()

@end

@implementation RegistViewController
- (void)dealloc
{
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self CreateView];
    [self creatButton];
}

-(void)CreateView
{
    NSArray *aArray = [NSArray arrayWithObjects:@"用户名", @"密码", @"确认密码", @"手机", @"邮箱", nil];
    NSArray *bArray = [NSArray arrayWithObjects:@"请输入用户名", @"请输入密码", @"请再次输入", @"请输入手机号", @"请输入邮箱", nil];
    int b = 1;
    for (int i = 0; i < [bArray count]; i++) {
        NSString *str = [aArray objectAtIndex:i];
        CustomView *cus = [[CustomView alloc] initWithFrame:CGRectMake(20, 100 + i * 70, 300, 40) text:str];
        cus.leftText.placeholder = [bArray objectAtIndex:i];
        cus.leftText.tag = b++;
        [self.view addSubview:cus];
        [cus release];
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (int i = 1; i < 6; i++) {
        UITextField * field = (UITextField *)[self.view viewWithTag:i];
        [field resignFirstResponder];
    }
}
- (void)creatButton
{

    UIButton * loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    loginButton.frame = CGRectMake(80, 480, 60, 40);
    [loginButton setTitle:@"注册" forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(foundButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];


    UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    cancelButton.frame = CGRectMake(260, 480, 60, 40);
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancelButton];
}

- (void)foundButtonAction:(id)sender
{

}
- (void)cancelButtonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}
## import "PassViewController.h 页面##
#import "PassViewController.h"
#import "CustomView.h"
@interface PassViewController ()

@end

@implementation PassViewController
- (void)dealloc
{
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self creatView];
}
- (void)creatView
{
    UITextField * mail = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 300, 40)];
    mail.placeholder = @"电子邮箱";
    mail.borderStyle = UITextBorderStyleRoundedRect;
    mail.keyboardType = UIKeyboardTypeEmailAddress;
    mail.clearsOnBeginEditing = YES;
    mail.tag = 123;
    [self.view addSubview:mail];
    [mail release];


    UIButton * foundButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [foundButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    foundButton.frame = CGRectMake(80, 160, 60, 40);
    [foundButton setTitle:@"找回" forState:UIControlStateNormal];
    [foundButton addTarget:self action:@selector(foundButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:foundButton];




    UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    cancelButton.frame = CGRectMake(260, 160, 60, 40);
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancelButton];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITextField *mail = (UITextField *)[self.view viewWithTag:123];

    [mail resignFirstResponder];
}

- (void)foundButtonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{

    }];


}
- (void)cancelButtonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}
## 标题 ##
#import <UIKit/UIKit.h>

@interface CustomView : UIView<UITextFieldDelegate>
@property (nonatomic, retain)UILabel *rightLable;
@property (nonatomic, retain)UITextField * leftText;
-(instancetype)initWithFrame:(CGRect)frame text:(NSString *)str;
@end
## 标题 ##
#import "CustomView.h"

@implementation CustomView
- (void)dealloc
{
    [super dealloc];
    [_leftText release];
    [_rightLable release];
}
- (instancetype)initWithFrame:(CGRect)frame text:(NSString *)str
{
    self = [super initWithFrame:frame];
    if (self) {
        self.rightLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width / 3 - 10, self.frame.size.height)];
        _rightLable.textAlignment = NSTextAlignmentLeft;
        _rightLable.text = str;
        _rightLable.font = [UIFont boldSystemFontOfSize:20];
        [self addSubview:_rightLable];
        [_rightLable release];

        self.leftText = [[UITextField alloc] initWithFrame:CGRectMake(self.frame.size.width / 3 + 20, 0, self.frame.size.width * 2 / 3 + 10, self.frame.size.height)];
        _leftText.font = [UIFont systemFontOfSize:20];
        _leftText.clearsOnBeginEditing = YES;
        _leftText.borderStyle = UITextBorderStyleRoundedRect;
        [self addSubview:_leftText];
        [_leftText release];

    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值