用基本控件简单地仿QQ登录界面

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

//  Created by 妖精的尾巴 on 15-8-14.

//  Copyright (c) 2015 妖精的尾巴. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()

{

    UILabel* backgroundLabel;//背景label

    UILabel* label1;//QQlabel

    UILabel* label2;//密码label

    UILabel* label3;//最下面label

    UITextField* textField1;//输入QQ号的UITextField

    UITextField* textField2;//输入QQ密码的UITextField

}

@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    [self createLabel];

    [self createTextField];

    [self createButton];

}

-(void)createLabel

{

    backgroundLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 130)];

    backgroundLabel.backgroundColor=[UIColor orangeColor];

    backgroundLabel.userInteractionEnabled=YES;

    [self.view addSubview:backgroundLabel];

    

    

    label1=[[UILabel alloc]initWithFrame:CGRectMake(20,30, 80, 30)];

    label1.text=@"QQ:";

    label1.textColor=[UIColor blackColor];

    label1.font=[UIFont systemFontOfSize:17];

    [backgroundLabel addSubview:label1];

    

    label2=[[UILabel alloc]initWithFrame:CGRectMake(20,70, 80, 30)];

    label2.text=@"密码:";

    label2.textColor=[UIColor blackColor];

    label2.font=[UIFont systemFontOfSize:17];

    [backgroundLabel addSubview:label2];

    

    label3=[[UILabel alloc]initWithFrame:CGRectMake(0, 200, 320, 30)];

    label3.backgroundColor=[UIColor greenColor];

    [self.view addSubview:label3];


}

-(void)createTextField

{

    textField1=[[UITextField alloc]initWithFrame:CGRectMake(80, 30, 190, 30)];

    textField1.borderStyle=UITextBorderStyleRoundedRect;

    textField1.font=[UIFont systemFontOfSize:14];

    textField1.placeholder=@"请输入QQ号码";

    textField1.keyboardType=UIKeyboardTypeNumberPad;

    [backgroundLabel addSubview:textField1];

    

    textField2=[[UITextField alloc]initWithFrame:CGRectMake(80, 70, 190, 30)];

    textField2.borderStyle=UITextBorderStyleRoundedRect;

    textField2.font=[UIFont systemFontOfSize:14];

    textField2.placeholder=@"请输入QQ密码";

    textField2.keyboardType=UIKeyboardTypeNumberPad;

    textField2.secureTextEntry=YES;

    [backgroundLabel addSubview:textField2];


}

-(void)createButton

{

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.backgroundColor=[UIColor blueColor];

    btn.layer.cornerRadius=10;

    [btn setTitle:@"登录" forState:UIControlStateNormal];

    btn.titleLabel.font=[UIFont systemFontOfSize:17];

    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    btn.frame=CGRectMake(110, 145, 90, 40);

    [btn  addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

}

-(void)btnClick

{

    NSLog(@"登录按钮被点击");

    /**

     *以下两句代码让键盘放弃第一响应者,自己退下

     */

    [textField1 resignFirstResponder];

    [textField2 resignFirstResponder];

    label3.text=[NSString stringWithFormat:@"QQ号为:%@的密码是:%@",textField1.text,textField2.text];

}


用基本控件简单地仿QQ登录界面_第1张图片

用基本控件简单地仿QQ登录界面_第2张图片

转载于:https://my.oschina.net/iOSliuhui/blog/492558

你可能感兴趣的:(用基本控件简单地仿QQ登录界面)