iOS--xuer(registration),iosregistrationid
這個登入頁麵包含了自適應螢幕的大小,數字使用者登入鍵盤是數字鍵台、隱藏鍵盤、隱藏密碼等等。
ViewController.h
#import <UIKit/UIKit.h>#import "UIViewExt.h"@interface ViewController : UIViewController<UITextFieldDelegate>/** * 背景圖片 */@property(strong,nonatomic) UIImageView *Imagebackgroud;/** * 使用者名稱輸入框 */@property(strong,nonatomic) UITextField *NameTextfild;/** * 密碼輸入框 */@property(strong,nonatomic) UITextField *PasswordTextfild;/** * 登入按鈕 */@property(strong,nonatomic) UIButton *LoginButton;/** * 註冊按鈕 */@property(strong,nonatomic) UIButton *RegistrationButton;@end
ViewController.m
#import "ViewController.h"#define WIDTH self.view.width#define HEIGHT self.view.height@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [self setBackgroudImage]; [self setLoginImage]; [self setTextFiled]; [self setButton];}#pragma Mark - 設定背景圖的方法-(void)setBackgroudImage{ self.Imagebackgroud=[[UIImageView alloc] initWithFrame:self.view.frame]; [self.Imagebackgroud setImage:[UIImage imageNamed:@"beijing"]]; [self.view addSubview:self.Imagebackgroud];}#pragma Mark - 設定輸入框-(void)setTextFiled{ // 使用者名稱輸入框設定 self.NameTextfild=[[UITextField alloc] initWithFrame:CGRectMake(WIDTH *0.1, HEIGHT *0.2, WIDTH*0.8, HEIGHT*0.05)]; self.NameTextfild.backgroundColor=[UIColor clearColor]; self.NameTextfild.placeholder=@"請輸入手機號"; // 設定輸入鍵盤為數字鍵台 self.NameTextfild.keyboardType=UIKeyboardTypeNumberPad; // 設定輸入框內的表徵圖 預設為不顯示 self.NameTextfild.leftView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"phoneIcon"]]; self.NameTextfild.leftViewMode=UITextFieldViewModeAlways; [self.view addSubview:self.NameTextfild]; // 設定使用者名稱輸入框下的線 UIView *Nameview=[[UIView alloc]initWithFrame:CGRectMake(WIDTH *0.1, HEIGHT *0.2+HEIGHT*0.05,WIDTH*0.8, 1)]; Nameview.backgroundColor=[UIColor whiteColor]; [self.view addSubview:Nameview]; // 密碼輸入框設定 self.PasswordTextfild=[[UITextField alloc] initWithFrame:CGRectMake(WIDTH *0.1,HEIGHT*0.2+HEIGHT*0.06, WIDTH*0.8, HEIGHT*0.05)]; self.PasswordTextfild.backgroundColor=[UIColor clearColor]; self.PasswordTextfild.placeholder=@"請輸入密碼"; // 設定輸入密碼保護(隱藏密碼) self.PasswordTextfild.secureTextEntry=YES; // 設定單擊return隱藏鍵盤需要代理 self.PasswordTextfild.delegate=self; // 設定輸入框內的表徵圖 預設為不顯示 self.PasswordTextfild.leftView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"passwordIcon"]]; self.PasswordTextfild.leftViewMode=UITextFieldViewModeAlways; [self.view addSubview:self.PasswordTextfild]; // 設定密碼輸入框下的線 UIView *Passwordview=[[UIView alloc]initWithFrame:CGRectMake(WIDTH *0.1,HEIGHT*0.31,WIDTH*0.8, 1)]; Passwordview.backgroundColor=[UIColor whiteColor]; [self.view addSubview:Passwordview];}#pragma Mark -按鈕設定方法-(void)setButton{ // 登入按鈕設定 self.LoginButton=[[UIButton alloc] initWithFrame:CGRectMake(WIDTH *0.1, HEIGHT*0.35, WIDTH *0.8, HEIGHT * 0.08)]; [self.LoginButton setBackgroundImage:[UIImage imageNamed:@"loginButton"] forState:UIControlStateNormal]; [self.LoginButton setTitle:@"登入" forState:UIControlStateNormal]; [self.view addSubview:self.LoginButton]; // 註冊按鈕設定 self.RegistrationButton=[[UIButton alloc] initWithFrame:CGRectMake(WIDTH *0.1, HEIGHT * 0.45, WIDTH *0.8, HEIGHT * 0.08)]; [self.RegistrationButton setBackgroundImage:[UIImage imageNamed:@"rigisterButton"] forState:UIControlStateNormal]; [self.RegistrationButton setTitle:@"註冊" forState:UIControlStateNormal]; [self.RegistrationButton setTitleColor:[UIColor colorWithRed:0.115 green:0.749 blue:0.769 alpha:1.000] forState:UIControlStateNormal]; [self.view addSubview:self.RegistrationButton];}#pragma Mark - logo圖片設定-(void)setLoginImage{ // 歡迎圖片設定 UIImageView *welcomeView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"welcome"]]; welcomeView.frame=CGRectMake(WIDTH *0.1, HEIGHT*0.05, WIDTH *0.8, HEIGHT *0.08); [self.view addSubview:welcomeView]; // logo圖片設定 UIImageView *LogoView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]]; LogoView.frame=CGRectMake(WIDTH*0.4, HEIGHT-HEIGHT*0.08, WIDTH*0.2, HEIGHT*0.03); [self.view addSubview:LogoView];}#pragma Mark - 設定鍵盤的隱藏/** * 單擊空白處隱藏鍵盤 * * @param touches 空白處 * @param event 單擊 */-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ if ([self.NameTextfild isFirstResponder]||[self.PasswordTextfild isFirstResponder]) { [self.NameTextfild resignFirstResponder]; [self.PasswordTextfild resignFirstResponder]; }}/** * 單擊return隱藏鍵盤 */-(BOOL)textFieldShouldReturn:(UITextField *)textField{ [self.PasswordTextfild resignFirstResponder]; return YES;}...@end
運行:
2016-04-06 22:22:01