iOS--xuer(registration),iosregistrationid

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.