1. 程式人生 > >iOS中QQ登入介面的製作,登入頁面和註冊頁面的切換

iOS中QQ登入介面的製作,登入頁面和註冊頁面的切換

1.首先將Label和TextField封裝成一個LTView的類,這樣每次建立可以直接生成一組Label和TextField。

command + n 建立一個LTView的類

將LTView.h的介面檔案裡,定義label和textField的例項變數:

@property (nonatomic,strong)UILabel *laber;

@property (nonatomic,strong)UITextField *textField;

 在LTView.m檔案中進行封裝:

self = [superinitWithFrame:frame];

if (self) {

self

.laber = [[UILabelalloc] initWithFrame:CGRectMake(0,0, width/3,height)];

        [selfaddSubview:self.laber];

self.laber.layer.borderWidth = 1;

self.laber.layer.cornerRadius = 5;

self.laber.textAlignment = NSTextAlignmentCenter;

self.textField = [[UITextFieldalloc] initWithFrame:CGRectMake(width

/3,0, width/3*2,height)];

self.textField.borderStyle =3;

        [selfaddSubview:self.textField];       

2.製作qq登入介面:

command + n 新建一個LoginView的類。

LoginView.h的介面檔案中設定全域性變數:

@classLTView;

@interface LoginView :UIView

@property (nonatomic,strong)LTView *usrName;

@property (nonatomic,strong)LTView

*PWD;

@property (nonatomic,strong)UIButton *loginButton;

@property (nonatomic,strong)UIButton *button1;

@property (nonatomic,strong)UIButton *button2;

@property (nonatomic,strong)UIButton *button3;

@end

LoginView.m中首先引入之前封裝好的LTView.h標頭檔案

- (instancetype)initWithFrame:(CGRect)frame

{

self = [superinitWithFrame:frame];

if (self) {

self.usrName = [[LTViewalloc] initWithFrame:CGRectMake(50,100, 200,30)];

self.usrName.laber.text = @"使用者名稱";

self.usrName.textField.placeholder = @"請輸入使用者名稱";

        [selfaddSubview:self.usrName];

self.PWD = [[LTViewalloc] initWithFrame:CGRectMake(50,150, 200,30)];

self.PWD.laber.text = @"密碼";

self.PWD.textField.placeholder = @"請輸入密碼";

self.PWD.textField.secureTextEntry = YES;

self.PWD.textField.clearsOnBeginEditing = YES;

        [selfaddSubview:self.PWD];

self.button1 = [UIButtonbuttonWithType:UIButtonTypeSystem];

        [self.button1setFrame:CGRectMake(50,200, 50,30)];

        [self.button1setTitle:@"登入"forState:UIControlStateNormal];

self.button1.layer.borderWidth = 1;

self.button1.layer.cornerRadius = 5;

        [self.button1setTitleColor:[UIColorredColor] forState:UIControlStateHighlighted];

        [selfaddSubview:self.button1];

self.button2 = [UIButtonbuttonWithType:UIButtonTypeSystem];

        [self.button2setFrame:CGRectMake(110,200, 80,30)];

        [self.button2setTitle:@"找回密碼"forState:UIControlStateNormal];

self.button2.layer.borderWidth = 1;

self.button2.layer.cornerRadius = 5;

        [selfaddSubview:self.button2];

self.button3 = [UIButtonbuttonWithType:UIButtonTypeSystem];

        [self.button3setFrame:CGRectMake(200,200, 50,30)];

        [self.button3setTitle:@"註冊"forState:UIControlStateNormal];

self.button3.layer.borderWidth = 1;

self.button3.layer.cornerRadius = 5;

        [selfaddSubview:self.button3];

    }

returnself;

}

3.製作使用者註冊頁面

command + n 建立一個RegistView的類

同樣第一步在RegistView.h檔案中設定全域性變數

@classLTView

@interface RegistView :UIView

@property (nonatomic,strong)LTView *userView;

@property (nonatomic,strong)LTView *PWD;

@property (nonatomic,strong)LTView *entetPWD;

@property (nonatomic,strong)LTView *phoneNum;

@property (nonatomic,strong)LTView *email;

@property (nonatomic,strong)UIButton *button1;

@property (nonatomic,strong)UIButton *button2;

@end

RegistView.m檔案中製作登入介面的內容

- (instancetype)initWithFrame:(CGRect)frame

{

self = [superinitWithFrame:frame];

if (self) {

self.userView = [[LTViewalloc] initWithFrame:CGRectMake(50,100, 200,30)];

self.userView.laber.text = @"使用者名稱";

self.userView.textField.placeholder = @"請輸入使用者名稱";

        [selfaddSubview: self.userView];       

self.PWD = [[LTViewalloc] initWithFrame:CGRectMake(50,150, 200,30)];

self.PWD.laber.text = @"密碼";

self.PWD.textField.placeholder = @"請輸入密碼";

self.PWD.textField.secureTextEntry = YES;

self.PWD.textField.clearsOnBeginEditing = YES;

        [selfaddSubview:self.PWD];        

self.entetPWD = [[LTViewalloc] initWithFrame:CGRectMake(50,200, 200,30)];

self.entetPWD.laber.text = @"確認密碼";

self.entetPWD.textField.secureTextEntry = YES;

self.entetPWD.textField.placeholder = @"再次確認密碼";

self.entetPWD.textField.clearsOnBeginEditing = YES;

        [selfaddSubview:self.entetPWD];       

self.phoneNum = [[LTViewalloc] initWithFrame:CGRectMake(50,250, 200,30)];

self.phoneNum.laber.text = @"手機號";;

self.phoneNum.textField.placeholder = @"請輸入聯絡方式";

        [selfaddSubview:self.phoneNum];       

self.email = [[LTViewalloc] initWithFrame:CGRectMake(50,300, 200,30)];

self.email.laber.text = @"郵箱";

self.email.textField.placeholder = @"請輸入郵箱";

        [selfaddSubview:self.email];        

self.button1 = [UIButtonbuttonWithType:UIButtonTypeSystem];

        [self.button1setFrame:CGRectMake(50,330, 90,30)];

        [self.button1setTitle:@"註冊"forState:UIControlStateNormal];

self.button1.layer.borderWidth = 1;

self.button1.layer.cornerRadius = 5;

        [selfaddSubview:self.button1];

self.button2 = [UIButtonbuttonWithType:UIButtonTypeSystem];

        [self.button2setFrame:CGRectMake(160,330, 90,30)];

        [self.button2setTitle:@"取消"forState:UIControlStateNormal];

self.button2.layer.borderWidth = 1;

self.button2.layer.cornerRadius = 5;

        [selfaddSubview:self.button2];        

    }

returnself;

}

4.ViewController檢視控制器來實現登入介面和註冊介面的顯示,介面切換

#pragma mark 懶載入 註冊頁面

- (RegistView *)registView{

if (!_registView) {

_registView = [[RegistViewalloc] init];

    }

return_registView;

}

//    載入頁面;

- (void)loadView{

    [superloadView];

self.loginView = [[LoginViewalloc] initWithFrame:[UIScreenmainScreen].bounds];

self.view =self.loginView;

}

//    新增按鍵功能;

- (void)viewDidLoad {

    [superviewDidLoad];

    [self.loginView.button3addTarget:selfaction:@selector(cancellation)forControlEvents:UIControlEventTouchUpInside];

    [self.registView.button2addTarget:selfaction:@selector(back)forControlEvents:UIControlEventTouchUpInside];

}

//   註冊鍵的功能實現;

- (void)cancellation{

self.view =self.registView;

}

//    返回鍵的功能實現;

- (void)back{

self.view =self.loginView;

}

現在來執行下程式


因為我們只設置了註冊鍵的功能,點選註冊鍵,就可以進入註冊介面


再次點選取消按鍵,既可以又返回到上一個頁面