登陸註冊界面

1、我的中心未登陸api

 

方法:ide

      加判斷登陸狀態直接打開我的中心頁面4,不然出現上面引導登陸或註冊入口顯示網站

代碼以下:spa

    

  1. #pragma mark addView   
  2. - (void)addView  
  3. {  
  4.     //背景圖   
  5.     [self.view setBackgroundColor:[UIColor whiteColor]];  
  6.     UIImageView *loginImgTips = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_tips.png"]];  
  7.     loginImgTips.frame = CGRectMake(33, 31, 255, 135);  
  8.     [self.view addSubview:loginImgTips];  
  9.     [loginImgTips release];  
  10.       
  11.     //登陸、註冊提示   
  12.     UILabel *loginLab = [[UILabel alloc] initWithFrame:CGRectMake(55, 43, 199, 80)];  
  13.     [loginLab setText:@"登陸工程師爸爸,網站收藏、iPhone下載、可方便哩!"];  
  14.     [loginLab setTextColor:[UIColor blackColor]];  
  15.     [loginLab setBackgroundColor:[UIColor clearColor]];  
  16.     [loginLab setNumberOfLines:3];  
  17.     [loginLab setFont:[UIFont systemFontOfSize:18]];  
  18.     [self.view addSubview:loginLab];  
  19.     [loginLab release];  
  20.       
  21.     //登陸   
  22.     UIButton *loginBtn = [[UIButton alloc] initWithFrame:CGRectMake(37, 180, 117, 37)];  
  23.     [loginBtn setBackgroundImage:[UIImage imageNamed:@"Button_login.png"] forState:UIControlStateNormal];  
  24.     [loginBtn setBackgroundImage:[UIImage imageNamed:@"Button_login@2x.png"] forState:UIControlStateHighlighted];  
  25.     [loginBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];  
  26.     [loginBtn setTag:101];  
  27.     [self.view addSubview:loginBtn];  
  28.     [loginBtn release];  
  29.       
  30.     //註冊   
  31.     UIButton *registerBtn = [[UIButton alloc] initWithFrame:CGRectMake(164, 180, 117, 37)];  
  32.     [registerBtn setBackgroundImage:[UIImage imageNamed:@"Button_reg.png"] forState:UIControlStateNormal];  
  33.     [registerBtn setBackgroundImage:[UIImage imageNamed:@"Button_reg@2x.png"] forState:UIControlStateHighlighted];  
  34.     [registerBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];  
  35.     [registerBtn setTag:102];  
  36.     [self.view addSubview:registerBtn];  
  37.     [registerBtn release];  
  38. }  
#pragma mark addView
- (void)addView
{
    //背景圖
    [self.view setBackgroundColor:[UIColor whiteColor]];
    UIImageView *loginImgTips = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_tips.png"]];
    loginImgTips.frame = CGRectMake(33, 31, 255, 135);
    [self.view addSubview:loginImgTips];
    [loginImgTips release];
    
    //登陸、註冊提示
    UILabel *loginLab = [[UILabel alloc] initWithFrame:CGRectMake(55, 43, 199, 80)];
    [loginLab setText:@"登陸工程師爸爸,網站收藏、iPhone下載、可方便哩!"];
    [loginLab setTextColor:[UIColor blackColor]];
    [loginLab setBackgroundColor:[UIColor clearColor]];
    [loginLab setNumberOfLines:3];
    [loginLab setFont:[UIFont systemFontOfSize:18]];
    [self.view addSubview:loginLab];
    [loginLab release];
    
    //登陸
    UIButton *loginBtn = [[UIButton alloc] initWithFrame:CGRectMake(37, 180, 117, 37)];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"Button_login.png"] forState:UIControlStateNormal];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"Button_login@2x.png"] forState:UIControlStateHighlighted];
    [loginBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [loginBtn setTag:101];
    [self.view addSubview:loginBtn];
    [loginBtn release];
    
    //註冊
    UIButton *registerBtn = [[UIButton alloc] initWithFrame:CGRectMake(164, 180, 117, 37)];
    [registerBtn setBackgroundImage:[UIImage imageNamed:@"Button_reg.png"] forState:UIControlStateNormal];
    [registerBtn setBackgroundImage:[UIImage imageNamed:@"Button_reg@2x.png"] forState:UIControlStateHighlighted];
    [registerBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [registerBtn setTag:102];
    [self.view addSubview:registerBtn];
    [registerBtn release];
}

 

2、登陸.net

頂部導航代碼:代理

 

  1. #pragma mark addNavBar   
  2. -(void) addNavBar  
  3. {      
  4.     //返回按鈕   
  5.     UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];  
  6.     [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back.png"] forState:UIControlStateNormal];  
  7.     [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back@2x.png"] forState:UIControlStateHighlighted];  
  8.     [btnLeft setTag:101];  
  9.     [btnLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];  
  10.     [btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];  
  11.     UIBarButtonItem *navBarBack = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];  
  12.     [btnLeft release];  
  13.       
  14.     [self.navigationItem setLeftBarButtonItem:navBarBack];  
  15.     [navBarBack release];  
  16.       
  17.     //右側完成   
  18.     UIBarButtonItem *navBarFinish = [[UIBarButtonItem alloc] initWithTitle:@"註冊" style:UIBarButtonItemStyleDone target:self action:@selector(btnClick:)];  
  19.     navBarFinish.tag = 102;  
  20.     self.navigationItem.rightBarButtonItem = navBarFinish;  
  21.     [navBarFinish release];  
  22. }  
#pragma mark addNavBar
-(void) addNavBar
{    
    //返回按鈕
    UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
    [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back.png"] forState:UIControlStateNormal];
    [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back@2x.png"] forState:UIControlStateHighlighted];
    [btnLeft setTag:101];
    [btnLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
    [btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *navBarBack = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
    [btnLeft release];
    
    [self.navigationItem setLeftBarButtonItem:navBarBack];
    [navBarBack release];
    
    //右側完成
    UIBarButtonItem *navBarFinish = [[UIBarButtonItem alloc] initWithTitle:@"註冊" style:UIBarButtonItemStyleDone target:self action:@selector(btnClick:)];
    navBarFinish.tag = 102;
    self.navigationItem.rightBarButtonItem = navBarFinish;
    [navBarFinish release];
}

 

 

登陸界面代碼實現以下:code

  1. #pragma mark addView   
  2. //建立輸入框   
  3. - (void)addInput  
  4. {  
  5.     //基本參數定義   
  6.     CGFloat padx   = 80.0f;  
  7.     _vFrame        = CGRectMake(10, 14, 300, 80);  
  8.     UIFont *lpFont = [UIFont boldSystemFontOfSize:16];  
  9.   
  10.     //郵箱和密碼背景顏色設置   
  11.     _view = [[UIView alloc] initWithFrame:_vFrame];  
  12.     _view.layer.cornerRadius = 8.0;  
  13.     _view.layer.borderWidth = 1;  
  14.     _view.layer.borderColor = [UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f].CGColor;  
  15.     [_view setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];  
  16.     [self.view addSubview:_view];  
  17.     [_view release];  
  18.       
  19.     //郵箱與密碼中間分割線   
  20.     UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, 55, 300, 1)];  
  21.     [line setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];  
  22.     [self.view addSubview:line];  
  23.     [line release];  
  24.       
  25.     //用戶名或Email   
  26.     UIImageView * _eview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250, 40)];  
  27.     [_eview setUserInteractionEnabled:YES];  
  28.     [_view addSubview:_eview];  
  29.     [_eview release];  
  30.       
  31.     UILabel *_unameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 55, 40)];  
  32.     [_unameLab setText:@"用戶名"];  
  33.     _unameLab.highlighted = YES;  
  34.     _unameLab.highlightedTextColor = [UIColor blackColor];  
  35.     [_unameLab setFont:lpFont];  
  36.     [_unameLab setBackgroundColor:[UIColor clearColor]];  
  37.     [_unameLab setTextColor:[UIColor blackColor]];  
  38.     [_view addSubview:_unameLab];  
  39.     [_unameLab release];  
  40.       
  41.     //用戶郵箱   
  42.     _email = [[UITextField alloc] initWithFrame:CGRectMake(padx, 15, 200, 40)];  
  43.     [_email setBackgroundColor:[UIColor clearColor]];  
  44.     [_email setKeyboardType:UIKeyboardTypeEmailAddress];  
  45.     [_email setTextColor:[UIColor grayColor]];      
  46.     //[_email setClearButtonMode:UITextFieldViewModeWhileEditing];  //編輯時會出現個修改X   
  47.     [_email setTag:101];  
  48.     [_email setReturnKeyType:UIReturnKeyNext];  //鍵盤下一步Next   
  49.     [_email setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫   
  50.     [_email setAutocorrectionType:UITextAutocorrectionTypeNo];  
  51.     [_email becomeFirstResponder]; //默認打開鍵盤   
  52.     [_email setFont:[UIFont systemFontOfSize:17]];  
  53.     [_email setDelegate:self];  
  54.     [_email setPlaceholder:@"用戶名或電子郵箱"];  
  55.     [_email setText:@""];  
  56.     [_email setHighlighted:YES];      
  57.     [_eview addSubview:_email];  
  58.       
  59.     //密碼   
  60.     UILabel *_passwdLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 43, 45, 40)];  
  61.     [_passwdLab setText:@"密  碼"];  
  62.     [_passwdLab setFont:lpFont];  
  63.     _passwdLab.highlighted = YES;  
  64.     _passwdLab.highlightedTextColor = [UIColor blackColor];  
  65.     [_passwdLab setBackgroundColor:[UIColor clearColor]];  
  66.     [_passwdLab setTextColor:[UIColor blackColor]];  
  67.     [_view addSubview:_passwdLab];  
  68.     [_passwdLab release];  
  69.       
  70.     _passwd = [[UITextField  alloc] initWithFrame:CGRectMake(padx, 53, 200, 40)];  
  71.     [_passwd setBackgroundColor:[UIColor clearColor]];  
  72.     [_passwd setKeyboardType:UIKeyboardTypeDefault];  
  73.     [_passwd setBorderStyle:UITextBorderStyleNone];  
  74.     [_passwd setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫   
  75.     [_passwd setReturnKeyType:UIReturnKeyDone]; //完成   
  76.     [_passwd setSecureTextEntry:YES]; //驗證   
  77.     [_passwd setDelegate:self];  
  78.     [_passwd setTag:102];  
  79.     [_passwd setTextColor:[UIColor grayColor]];  
  80.     [_passwd setFont:lpFont];  
  81.     [_passwd setText:@""  
  82.     [_view addSubview:_passwd];   
  83. }  
#pragma mark addView
//建立輸入框
- (void)addInput
{
    //基本參數定義
    CGFloat padx   = 80.0f;
    _vFrame        = CGRectMake(10, 14, 300, 80);
    UIFont *lpFont = [UIFont boldSystemFontOfSize:16];

    //郵箱和密碼背景顏色設置
    _view = [[UIView alloc] initWithFrame:_vFrame];
    _view.layer.cornerRadius = 8.0;
    _view.layer.borderWidth = 1;
    _view.layer.borderColor = [UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f].CGColor;
    [_view setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];
    [self.view addSubview:_view];
    [_view release];
    
    //郵箱與密碼中間分割線
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, 55, 300, 1)];
    [line setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];
    [self.view addSubview:line];
    [line release];
    
    //用戶名或Email
    UIImageView * _eview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250, 40)];
    [_eview setUserInteractionEnabled:YES];
    [_view addSubview:_eview];
    [_eview release];
    
    UILabel *_unameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 55, 40)];
    [_unameLab setText:@"用戶名"];
    _unameLab.highlighted = YES;
    _unameLab.highlightedTextColor = [UIColor blackColor];
    [_unameLab setFont:lpFont];
    [_unameLab setBackgroundColor:[UIColor clearColor]];
    [_unameLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_unameLab];
    [_unameLab release];
    
    //用戶郵箱
    _email = [[UITextField alloc] initWithFrame:CGRectMake(padx, 15, 200, 40)];
    [_email setBackgroundColor:[UIColor clearColor]];
    [_email setKeyboardType:UIKeyboardTypeEmailAddress];
    [_email setTextColor:[UIColor grayColor]];    
    //[_email setClearButtonMode:UITextFieldViewModeWhileEditing];  //編輯時會出現個修改X
    [_email setTag:101];
    [_email setReturnKeyType:UIReturnKeyNext];  //鍵盤下一步Next
    [_email setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫
    [_email setAutocorrectionType:UITextAutocorrectionTypeNo];
    [_email becomeFirstResponder]; //默認打開鍵盤
    [_email setFont:[UIFont systemFontOfSize:17]];
    [_email setDelegate:self];
    [_email setPlaceholder:@"用戶名或電子郵箱"];
    [_email setText:@""];
    [_email setHighlighted:YES];    
    [_eview addSubview:_email];
    
    //密碼
    UILabel *_passwdLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 43, 45, 40)];
    [_passwdLab setText:@"密  碼"];
    [_passwdLab setFont:lpFont];
    _passwdLab.highlighted = YES;
    _passwdLab.highlightedTextColor = [UIColor blackColor];
    [_passwdLab setBackgroundColor:[UIColor clearColor]];
    [_passwdLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_passwdLab];
    [_passwdLab release];
    
    _passwd = [[UITextField  alloc] initWithFrame:CGRectMake(padx, 53, 200, 40)];
    [_passwd setBackgroundColor:[UIColor clearColor]];
    [_passwd setKeyboardType:UIKeyboardTypeDefault];
    [_passwd setBorderStyle:UITextBorderStyleNone];
    [_passwd setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫
    [_passwd setReturnKeyType:UIReturnKeyDone]; //完成
    [_passwd setSecureTextEntry:YES]; //驗證
    [_passwd setDelegate:self];
    [_passwd setTag:102];
    [_passwd setTextColor:[UIColor grayColor]];
    [_passwd setFont:lpFont];
    [_passwd setText:@""
    [_view addSubview:_passwd]; 
}

3、註冊
orm

頂部導航控制,代碼實現以下:blog

 

  1. - (void)addNavBar  
  2. {  
  3.     if (_step == 1) {  
  4.         [self setXDNav:YES];  
  5.           
  6.         //返回按鈕   
  7.         UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];  
  8.         [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back.png"] forState:UIControlStateNormal];  
  9.         [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back@2x.png"] forState:UIControlStateHighlighted];  
  10.         [btnLeft setTag:101];  
  11.         [btnLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];  
  12.         [btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];  
  13.         UIBarButtonItem *navBarBack = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];  
  14.         [btnLeft release];  
  15.         [self.navigationItem setLeftBarButtonItem:navBarBack];  
  16.         [navBarBack release];  
  17.           
  18.         //設標題   
  19.         [self setXDTitle:@"註冊" pageName:@""];  
  20.           
  21.         //添加返回按鈕   
  22.           
  23.         [self addInputOne]; //註冊第一步   
  24.     }else{  
  25.         [self setXDTitle:@"寶貝信息設置" pageName:@""];  
  26.                   
  27.         //返回按鈕   
  28.         UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];  
  29.         [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back.png"] forState:UIControlStateNormal];  
  30.         [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back@2x.png"] forState:UIControlStateHighlighted];  
  31.         [btnLeft setTag:101];  
  32.         [btnLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];  
  33.         [btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];  
  34.         UIBarButtonItem *navBarBack = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];  
  35.         [btnLeft release];  
  36.           
  37.         [self.navigationItem setLeftBarButtonItem:navBarBack];  
  38.         [navBarBack release];          
  39.           
  40.         //右側完成   
  41.         UIBarButtonItem *navBarFinish = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(btnClick:)];  
  42.         navBarFinish.tag = 102;  
  43.         //[_navBarFinish addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];   
  44.         self.navigationItem.rightBarButtonItem = navBarFinish;  
  45.         [navBarFinish release];  
  46.         [self addInputTow];  
  47.     }  
  48. }  
- (void)addNavBar
{
    if (_step == 1) {
        [self setXDNav:YES];
        
        //返回按鈕
        UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
        [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back.png"] forState:UIControlStateNormal];
        [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back@2x.png"] forState:UIControlStateHighlighted];
        [btnLeft setTag:101];
        [btnLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
        [btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *navBarBack = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
        [btnLeft release];
        [self.navigationItem setLeftBarButtonItem:navBarBack];
        [navBarBack release];
        
        //設標題
        [self setXDTitle:@"註冊" pageName:@""];
        
        //添加返回按鈕
        
        [self addInputOne]; //註冊第一步
    }else{
        [self setXDTitle:@"寶貝信息設置" pageName:@""];
                
        //返回按鈕
        UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
        [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back.png"] forState:UIControlStateNormal];
        [btnLeft setBackgroundImage:[UIImage imageNamed:@"item_back@2x.png"] forState:UIControlStateHighlighted];
        [btnLeft setTag:101];
        [btnLeft.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
        [btnLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *navBarBack = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
        [btnLeft release];
        
        [self.navigationItem setLeftBarButtonItem:navBarBack];
        [navBarBack release];        
        
        //右側完成
        UIBarButtonItem *navBarFinish = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(btnClick:)];
        navBarFinish.tag = 102;
        //[_navBarFinish addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = navBarFinish;
        [navBarFinish release];
        [self addInputTow];
    }
}

 

註冊分兩步:事件

第一步基本信息註冊,代碼以下

 

  1. //建立輸入框   
  2. - (void)addInputOne  
  3. {  
  4.     //基本參數定義   
  5.     CGFloat padx   = 95.0f;  
  6.     _vFrame        = CGRectMake(10, 14, 300, 125);  
  7.     UIFont *lpFont = [UIFont boldSystemFontOfSize:16];  
  8.       
  9.     //郵箱和密碼背景顏色設置   
  10.     _view = [[UIView alloc] initWithFrame:_vFrame];  
  11.     _view.layer.cornerRadius = 8.0;  
  12.     _view.layer.borderWidth = 1;  
  13.     _view.layer.borderColor = [UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f].CGColor;  
  14.     [_view setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];  
  15.     [self.view addSubview:_view];  
  16.     [_view release];  
  17.           
  18.     //用戶名與密碼中間分割線   
  19.     UIView *lineOne = [[UIView alloc] initWithFrame:CGRectMake(10, 53, 300, 1)];  
  20.     [lineOne setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];  
  21.     [self.view addSubview:lineOne];  
  22.     [lineOne release];  
  23.       
  24.     //用戶名   
  25.     UILabel *_unameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 2, 55, 40)];  
  26.     [_unameLab setText:@"用戶名"];  
  27.     _unameLab.highlighted = YES;  
  28.     _unameLab.highlightedTextColor = [UIColor blackColor];  
  29.     [_unameLab setFont:lpFont];  
  30.     [_unameLab setBackgroundColor:[UIColor clearColor]];  
  31.     [_unameLab setTextColor:[UIColor blackColor]];  
  32.     [_view addSubview:_unameLab];  
  33.     [_unameLab release];  
  34.       
  35.     _uname = [[UITextField alloc] initWithFrame:CGRectMake(padx, 10, 230, 40)];  
  36.     [_uname setBackgroundColor:[UIColor clearColor]];  
  37.     [_uname setTag:101];  
  38.     [_uname setUserInteractionEnabled:YES];  
  39.     [_uname setKeyboardType:UIKeyboardTypeDefault];  
  40.     [_uname setReturnKeyType:UIReturnKeyNext];  //鍵盤下一步Next   
  41.     [_uname setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫   
  42.     [_uname setAutocorrectionType:UITextAutocorrectionTypeNo];  
  43.     [_uname setReturnKeyType:UIReturnKeyNext]; //下一個Passwd   
  44.     [_uname becomeFirstResponder]; //默認打開鍵盤   
  45.     [_uname setFont:[UIFont systemFontOfSize:17]];  
  46.     [_uname setDelegate:self];  
  47.     [_uname setText:@""];  
  48.     [_uname setHighlighted:YES];  
  49.     [_view addSubview:_uname];  
  50.       
  51.     //密碼   
  52.     UILabel *_passwdLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 43, 45, 40)];  
  53.     [_passwdLab setText:@"密  碼"];  
  54.     [_passwdLab setFont:lpFont];  
  55.     _passwdLab.highlighted = YES;  
  56.     _passwdLab.highlightedTextColor = [UIColor blackColor];  
  57.     [_passwdLab setBackgroundColor:[UIColor clearColor]];  
  58.     [_passwdLab setTextColor:[UIColor blackColor]];  
  59.     [_view addSubview:_passwdLab];  
  60.     [_passwdLab release];  
  61.       
  62.     _passwd = [[UITextField  alloc] initWithFrame:CGRectMake(padx, 53, 200, 40)];  
  63.     [_passwd setBackgroundColor:[UIColor clearColor]];  
  64.     [_passwd setKeyboardType:UIKeyboardTypeDefault];  
  65.     [_passwd setBorderStyle:UITextBorderStyleNone];  
  66.     [_passwd setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫   
  67.     [_passwd setReturnKeyType:UIReturnKeyNext]; //下一個Email   
  68.     [_passwd setSecureTextEntry:YES]; //驗證   
  69.     [_passwd setDelegate:self];  
  70.     [_passwd setTag:102];  
  71.     [_passwd setTextColor:[UIColor grayColor]];  
  72.     [_passwd setFont:lpFont];  
  73.     [_passwd setText:@""];  
  74.     [_view addSubview:_passwd];  
  75.       
  76.     //郵箱與密碼中間分割線   
  77.     UIView *lineTow = [[UIView alloc] initWithFrame:CGRectMake(10, 95, 300, 1)];  
  78.     [lineTow setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];  
  79.     [self.view addSubview:lineTow];  
  80.     [lineTow release];  
  81.       
  82.     //用戶郵箱   
  83.     UILabel *_emailLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 82, 280, 40)];  
  84.     [_emailLab setText:@"電子郵箱"];  
  85.     _emailLab.highlighted = YES;  
  86.     _emailLab.highlightedTextColor = [UIColor blackColor];  
  87.     [_emailLab setFont:lpFont];  
  88.     [_emailLab setBackgroundColor:[UIColor clearColor]];  
  89.     [_emailLab setTextColor:[UIColor blackColor]];  
  90.     [_view addSubview:_emailLab];  
  91.     [_emailLab release];  
  92.   
  93.     _email = [[UITextField alloc] initWithFrame:CGRectMake(padx, 92, 200, 40)];  
  94.     [_email setBackgroundColor:[UIColor clearColor]];  
  95.     [_email setKeyboardType:UIKeyboardTypeEmailAddress];  
  96.     [_email setTextColor:[UIColor grayColor]];  
  97.     [_email setTag:103];  
  98.     [_email setReturnKeyType:UIReturnKeyDone];  //鍵盤下一步Next   
  99.     [_email setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫   
  100.     [_email setAutocorrectionType:UITextAutocorrectionTypeNo];      
  101.     [_email setFont:[UIFont systemFontOfSize:17]];  
  102.     [_email setDelegate:self];  
  103.     [_email setPlaceholder:@"devdiy@example.com"];  
  104.     [_email setText:@""];  
  105.     [_email setHighlighted:YES];  
  106.     [_view addSubview:_email];  
  107. }  
//建立輸入框
- (void)addInputOne
{
    //基本參數定義
    CGFloat padx   = 95.0f;
    _vFrame        = CGRectMake(10, 14, 300, 125);
    UIFont *lpFont = [UIFont boldSystemFontOfSize:16];
    
    //郵箱和密碼背景顏色設置
    _view = [[UIView alloc] initWithFrame:_vFrame];
    _view.layer.cornerRadius = 8.0;
    _view.layer.borderWidth = 1;
    _view.layer.borderColor = [UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f].CGColor;
    [_view setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];
    [self.view addSubview:_view];
    [_view release];
        
    //用戶名與密碼中間分割線
    UIView *lineOne = [[UIView alloc] initWithFrame:CGRectMake(10, 53, 300, 1)];
    [lineOne setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];
    [self.view addSubview:lineOne];
    [lineOne release];
    
    //用戶名
    UILabel *_unameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 2, 55, 40)];
    [_unameLab setText:@"用戶名"];
    _unameLab.highlighted = YES;
    _unameLab.highlightedTextColor = [UIColor blackColor];
    [_unameLab setFont:lpFont];
    [_unameLab setBackgroundColor:[UIColor clearColor]];
    [_unameLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_unameLab];
    [_unameLab release];
    
    _uname = [[UITextField alloc] initWithFrame:CGRectMake(padx, 10, 230, 40)];
    [_uname setBackgroundColor:[UIColor clearColor]];
    [_uname setTag:101];
    [_uname setUserInteractionEnabled:YES];
    [_uname setKeyboardType:UIKeyboardTypeDefault];
    [_uname setReturnKeyType:UIReturnKeyNext];  //鍵盤下一步Next
    [_uname setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫
    [_uname setAutocorrectionType:UITextAutocorrectionTypeNo];
    [_uname setReturnKeyType:UIReturnKeyNext]; //下一個Passwd
    [_uname becomeFirstResponder]; //默認打開鍵盤
    [_uname setFont:[UIFont systemFontOfSize:17]];
    [_uname setDelegate:self];
    [_uname setText:@""];
    [_uname setHighlighted:YES];
    [_view addSubview:_uname];
    
    //密碼
    UILabel *_passwdLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 43, 45, 40)];
    [_passwdLab setText:@"密  碼"];
    [_passwdLab setFont:lpFont];
    _passwdLab.highlighted = YES;
    _passwdLab.highlightedTextColor = [UIColor blackColor];
    [_passwdLab setBackgroundColor:[UIColor clearColor]];
    [_passwdLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_passwdLab];
    [_passwdLab release];
    
    _passwd = [[UITextField  alloc] initWithFrame:CGRectMake(padx, 53, 200, 40)];
    [_passwd setBackgroundColor:[UIColor clearColor]];
    [_passwd setKeyboardType:UIKeyboardTypeDefault];
    [_passwd setBorderStyle:UITextBorderStyleNone];
    [_passwd setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫
    [_passwd setReturnKeyType:UIReturnKeyNext]; //下一個Email
    [_passwd setSecureTextEntry:YES]; //驗證
    [_passwd setDelegate:self];
    [_passwd setTag:102];
    [_passwd setTextColor:[UIColor grayColor]];
    [_passwd setFont:lpFont];
    [_passwd setText:@""];
    [_view addSubview:_passwd];
    
    //郵箱與密碼中間分割線
    UIView *lineTow = [[UIView alloc] initWithFrame:CGRectMake(10, 95, 300, 1)];
    [lineTow setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];
    [self.view addSubview:lineTow];
    [lineTow release];
    
    //用戶郵箱
    UILabel *_emailLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 82, 280, 40)];
    [_emailLab setText:@"電子郵箱"];
    _emailLab.highlighted = YES;
    _emailLab.highlightedTextColor = [UIColor blackColor];
    [_emailLab setFont:lpFont];
    [_emailLab setBackgroundColor:[UIColor clearColor]];
    [_emailLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_emailLab];
    [_emailLab release];

    _email = [[UITextField alloc] initWithFrame:CGRectMake(padx, 92, 200, 40)];
    [_email setBackgroundColor:[UIColor clearColor]];
    [_email setKeyboardType:UIKeyboardTypeEmailAddress];
    [_email setTextColor:[UIColor grayColor]];
    [_email setTag:103];
    [_email setReturnKeyType:UIReturnKeyDone];  //鍵盤下一步Next
    [_email setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫
    [_email setAutocorrectionType:UITextAutocorrectionTypeNo];    
    [_email setFont:[UIFont systemFontOfSize:17]];
    [_email setDelegate:self];
    [_email setPlaceholder:@"devdiy@example.com"];
    [_email setText:@""];
    [_email setHighlighted:YES];
    [_view addSubview:_email];
}

第二步完善資源輸入,代碼實現以下:

 

 

  1. //建立輸入框   
  2. - (void)addInputTow  
  3. {  
  4.     //基本參數定義   
  5.     CGFloat padx   = 100.0f;  
  6.     _vFrame        = CGRectMake(10, 10, 300, 125);  
  7.     UIFont *lpFont = [UIFont boldSystemFontOfSize:16];  
  8.       
  9.     //寶貝小名、寶貝性別、寶貝生日背景顏色設置   
  10.     _view = [[UIView alloc] initWithFrame:_vFrame];  
  11.     _view.layer.cornerRadius = 8.0;  
  12.     _view.layer.borderWidth = 1;  
  13.     _view.layer.borderColor = [UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f].CGColor;  
  14.     [_view setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];  
  15.     [self.view addSubview:_view];  
  16.     [_view release];  
  17.       
  18.     //寶貝小名和寶貝性別分割線   
  19.     UIView *lineOne = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 1)];  
  20.     [lineOne setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];  
  21.     [self.view addSubview:lineOne];  
  22.     [lineOne release];  
  23.       
  24.     //寶貝小名   
  25.     UILabel *_nicknameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 2, 75, 40)];  
  26.     [_nicknameLab setText:@"寶貝小名"];  
  27.     _nicknameLab.highlighted = YES;  
  28.     _nicknameLab.highlightedTextColor = [UIColor blackColor];  
  29.     [_nicknameLab setFont:lpFont];  
  30.     [_nicknameLab setBackgroundColor:[UIColor clearColor]];  
  31.     [_nicknameLab setTextColor:[UIColor blackColor]];  
  32.     [_view addSubview:_nicknameLab];  
  33.     [_nicknameLab release];  
  34.       
  35.     _nickname = [[UITextField alloc] initWithFrame:CGRectMake(padx, 13, 180, 40)];  
  36.     [_nickname setBackgroundColor:[UIColor clearColor]];  
  37.     [_nickname setTag:101];  
  38.     [_nickname setUserInteractionEnabled:YES];  
  39.     [_nickname setKeyboardType:UIKeyboardTypeDefault];  
  40.     [_nickname setReturnKeyType:UIReturnKeyNext];  //鍵盤下一步Next   
  41.     [_nickname setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫   
  42.     [_nickname setAutocorrectionType:UITextAutocorrectionTypeNo];  
  43.     [_nickname setReturnKeyType:UIReturnKeyNext]; //下一個寶貝性別   
  44.     [_nickname becomeFirstResponder]; //默認打開鍵盤   
  45.     [_nickname setFont:[UIFont systemFontOfSize:17]];  
  46.     [_nickname setDelegate:self];  
  47.     [_nickname setText:@""];  
  48.     [_nickname setHighlighted:YES];  
  49.     [_view addSubview:_nickname];  
  50.       
  51.     //寶貝性別   
  52.     UILabel *_sexLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 35, 75, 50)];  
  53.     [_sexLab setText:@"寶貝性別"];  
  54.     [_sexLab setFont:lpFont];  
  55.     _sexLab.highlighted = YES;  
  56.     _sexLab.highlightedTextColor = [UIColor blackColor];  
  57.     [_sexLab setBackgroundColor:[UIColor clearColor]];  
  58.     [_sexLab setTextColor:[UIColor blackColor]];  
  59.     [_view addSubview:_sexLab];  
  60.     [_sexLab release];  
  61.   
  62.     _segment = [[UISegmentedControl alloc] initWithItems:  
  63.                                    [NSArray arrayWithObjects:  
  64.                                     @"男",@"女",  
  65.                                     nil]];  
  66.     _segment.frame = CGRectMake(padx+10, 56, 130, 32);  
  67.     _segment.segmentedControlStyle = UISegmentedControlStylePlain;  
  68.     _segment.selectedSegmentIndex = 1;  
  69.     [self.view addSubview:_segment];  
  70.     [_segment release];  
  71.       
  72.     //寶貝性別與寶貝生日中間分割線   
  73.     UIView *lineTow = [[UIView alloc] initWithFrame:CGRectMake(10, 93, 300, 1)];  
  74.     [lineTow setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];  
  75.     [self.view addSubview:lineTow];  
  76.     [lineTow release];  
  77.       
  78.     //寶貝生日   
  79.     UILabel *_birthLab = [[UILabel alloc] initWithFrame:CGRectMake(30, 96, 75, 40)];  
  80.     [_birthLab setText:@"寶貝生日"];  
  81.     _birthLab.highlighted = YES;  
  82.     _birthLab.highlightedTextColor = [UIColor blackColor];  
  83.     [_birthLab setFont:lpFont];  
  84.     [_birthLab setBackgroundColor:[UIColor clearColor]];  
  85.     [_birthLab setTextColor:[UIColor blackColor]];  
  86.     [self.view addSubview:_birthLab];  
  87.     [_birthLab release];  
  88.           
  89.     _birthDay = [[UIButton alloc] initWithFrame:CGRectMake(57, 96, 200, 40)];  
  90.     [_birthDay setBackgroundColor:[UIColor clearColor]];  
  91.     [_birthDay setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  
  92.     [_birthDay setTitle:@"2004-10-09" forState:UIControlStateNormal];  
  93.     [_birthDay setTag:104];  
  94.     [_birthDay addTarget:self action:@selector(openBirthday) forControlEvents:UIControlEventTouchUpInside];  
  95.     [_birthDay setHighlighted:YES];  
  96.     [self.view addSubview:_birthDay];  
  97.       
  98.     //寶貝信息提示   
  99.     UILabel *_babyNote = [[UILabel alloc] initWithFrame:CGRectMake(45, 131, 300, 40)];  
  100.     [_babyNote setBackgroundColor:[UIColor clearColor]];  
  101.     [_babyNote setTextColor:[UIColor colorWithRed:83.0f/255.0f green:92.0f/255.0f blue:112.0f/255.0f alpha:1.0f]];  
  102.     [_babyNote setTag:104];  
  103.     [_babyNote setFont:[UIFont systemFontOfSize:14]];  
  104.     [_babyNote setText:@"推薦引擎會根據孩子信息進行個性推薦"];  
  105.     [_babyNote setHighlighted:YES];  
  106.     [self.view addSubview:_babyNote];  
  107.     [_babyNote release];  
  108.           
  109.     //初始日期選擇控件   
  110.     _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 200.0, 0.0, 0.0)];  
  111.     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];      
  112.     [dateFormatter setDateFormat:@"yyyy-MM-dd"];  
  113.   
  114.     //將當前生日時間設置到日期輪軸上   
  115.     _datePicker.date = [dateFormatter dateFromString:_birthDay.titleLabel.text];  
  116.       
  117.     //設置爲中文顯示   
  118.     NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];  
  119.     _datePicker.locale = locale;  
  120.     [locale release];  
  121.     [_datePicker setDatePickerMode:UIDatePickerModeDate];  
  122.       
  123.     [_datePicker addTarget:self action:@selector(dataValueChanged) forControlEvents:UIControlEventValueChanged];  
  124.     [self.view addSubview:_datePicker];  
  125. }  
//建立輸入框
- (void)addInputTow
{
    //基本參數定義
    CGFloat padx   = 100.0f;
    _vFrame        = CGRectMake(10, 10, 300, 125);
    UIFont *lpFont = [UIFont boldSystemFontOfSize:16];
    
    //寶貝小名、寶貝性別、寶貝生日背景顏色設置
    _view = [[UIView alloc] initWithFrame:_vFrame];
    _view.layer.cornerRadius = 8.0;
    _view.layer.borderWidth = 1;
    _view.layer.borderColor = [UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f].CGColor;
    [_view setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];
    [self.view addSubview:_view];
    [_view release];
    
    //寶貝小名和寶貝性別分割線
    UIView *lineOne = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 1)];
    [lineOne setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];
    [self.view addSubview:lineOne];
    [lineOne release];
    
    //寶貝小名
    UILabel *_nicknameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 2, 75, 40)];
    [_nicknameLab setText:@"寶貝小名"];
    _nicknameLab.highlighted = YES;
    _nicknameLab.highlightedTextColor = [UIColor blackColor];
    [_nicknameLab setFont:lpFont];
    [_nicknameLab setBackgroundColor:[UIColor clearColor]];
    [_nicknameLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_nicknameLab];
    [_nicknameLab release];
    
    _nickname = [[UITextField alloc] initWithFrame:CGRectMake(padx, 13, 180, 40)];
    [_nickname setBackgroundColor:[UIColor clearColor]];
    [_nickname setTag:101];
    [_nickname setUserInteractionEnabled:YES];
    [_nickname setKeyboardType:UIKeyboardTypeDefault];
    [_nickname setReturnKeyType:UIReturnKeyNext];  //鍵盤下一步Next
    [_nickname setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關閉首字母大寫
    [_nickname setAutocorrectionType:UITextAutocorrectionTypeNo];
    [_nickname setReturnKeyType:UIReturnKeyNext]; //下一個寶貝性別
    [_nickname becomeFirstResponder]; //默認打開鍵盤
    [_nickname setFont:[UIFont systemFontOfSize:17]];
    [_nickname setDelegate:self];
    [_nickname setText:@""];
    [_nickname setHighlighted:YES];
    [_view addSubview:_nickname];
    
    //寶貝性別
    UILabel *_sexLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 35, 75, 50)];
    [_sexLab setText:@"寶貝性別"];
    [_sexLab setFont:lpFont];
    _sexLab.highlighted = YES;
    _sexLab.highlightedTextColor = [UIColor blackColor];
    [_sexLab setBackgroundColor:[UIColor clearColor]];
    [_sexLab setTextColor:[UIColor blackColor]];
    [_view addSubview:_sexLab];
    [_sexLab release];

    _segment = [[UISegmentedControl alloc] initWithItems:
                                   [NSArray arrayWithObjects:
                                    @"男",@"女",
                                    nil]];
    _segment.frame = CGRectMake(padx+10, 56, 130, 32);
    _segment.segmentedControlStyle = UISegmentedControlStylePlain;
    _segment.selectedSegmentIndex = 1;
    [self.view addSubview:_segment];
    [_segment release];
    
    //寶貝性別與寶貝生日中間分割線
    UIView *lineTow = [[UIView alloc] initWithFrame:CGRectMake(10, 93, 300, 1)];
    [lineTow setBackgroundColor:[UIColor colorWithRed:209.0f/255.0f green:209.0f/255.0f blue:209.0f/255.0f alpha:1.0f]];
    [self.view addSubview:lineTow];
    [lineTow release];
    
    //寶貝生日
    UILabel *_birthLab = [[UILabel alloc] initWithFrame:CGRectMake(30, 96, 75, 40)];
    [_birthLab setText:@"寶貝生日"];
    _birthLab.highlighted = YES;
    _birthLab.highlightedTextColor = [UIColor blackColor];
    [_birthLab setFont:lpFont];
    [_birthLab setBackgroundColor:[UIColor clearColor]];
    [_birthLab setTextColor:[UIColor blackColor]];
    [self.view addSubview:_birthLab];
    [_birthLab release];
        
    _birthDay = [[UIButton alloc] initWithFrame:CGRectMake(57, 96, 200, 40)];
    [_birthDay setBackgroundColor:[UIColor clearColor]];
    [_birthDay setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_birthDay setTitle:@"2004-10-09" forState:UIControlStateNormal];
    [_birthDay setTag:104];
    [_birthDay addTarget:self action:@selector(openBirthday) forControlEvents:UIControlEventTouchUpInside];
    [_birthDay setHighlighted:YES];
    [self.view addSubview:_birthDay];
    
    //寶貝信息提示
    UILabel *_babyNote = [[UILabel alloc] initWithFrame:CGRectMake(45, 131, 300, 40)];
    [_babyNote setBackgroundColor:[UIColor clearColor]];
    [_babyNote setTextColor:[UIColor colorWithRed:83.0f/255.0f green:92.0f/255.0f blue:112.0f/255.0f alpha:1.0f]];
    [_babyNote setTag:104];
    [_babyNote setFont:[UIFont systemFontOfSize:14]];
    [_babyNote setText:@"推薦引擎會根據孩子信息進行個性推薦"];
    [_babyNote setHighlighted:YES];
    [self.view addSubview:_babyNote];
    [_babyNote release];
        
    //初始日期選擇控件
    _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 200.0, 0.0, 0.0)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];

    //將當前生日時間設置到日期輪軸上
    _datePicker.date = [dateFormatter dateFromString:_birthDay.titleLabel.text];
    
    //設置爲中文顯示
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    _datePicker.locale = locale;
    [locale release];
    [_datePicker setDatePickerMode:UIDatePickerModeDate];
    
    [_datePicker addTarget:self action:@selector(dataValueChanged) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_datePicker];
}


3、註冊,登陸成功後直接進入我的中心頁

 


頂部界面代碼實現以下:

 

  1. #pragma mark addHeadView   
  2. - (void)addHeadView  
  3. {  
  4.     //頭像背景設置   
  5.     UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 84)];  
  6.     [headView setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];  
  7.       
  8.     //按鈕方式添加左側用頭像   
  9.     UIButton *headBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 64, 64)];  
  10.     [headBtn setBackgroundImage:[UIImage imageNamed:@"Baby_head.png"] forState:UIControlStateNormal];  
  11.     headBtn.layer.cornerRadius = 8.0;  
  12.     headBtn.layer.masksToBounds = YES;  
  13.     [headView addSubview:headBtn];  
  14.     [headBtn release];  
  15.     [self.view addSubview:headView];  
  16.       
  17.     //用戶名   
  18.     UILabel *unameLab = [[UILabel alloc] initWithFrame:CGRectMake(89, 15, 200, 20)];  
  19.     [unameLab setText:@"balbaba"];  
  20.     [unameLab setTextColor:[UIColor blackColor]];  
  21.     [unameLab setFont:[UIFont boldSystemFontOfSize:16]];  
  22.     [unameLab setBackgroundColor:[UIColor clearColor]];  
  23.     [headView addSubview:unameLab];  
  24.       
  25.     //寶貝頭像小圖   
  26.     UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(89, 38, 24, 24)];  
  27.     [iconView setImage:[UIImage imageNamed:@"Baby_gender_boy.png"]];      
  28.     [headView addSubview:iconView];  
  29.       
  30.     //寶貝暱稱   
  31.     UILabel *nicknameLab = [[UILabel alloc] initWithFrame:CGRectMake(120, 40, 120, 20)];  
  32.     [nicknameLab setText:@"寶貝qgggfgghhjjjk"];  
  33.     [nicknameLab setTextColor:[UIColor blackColor]];  
  34.     [nicknameLab setFont:[UIFont systemFontOfSize:14]];  
  35.     [nicknameLab setBackgroundColor:[UIColor clearColor]];  
  36.     [headView addSubview:nicknameLab];  
  37.       
  38.     //寶貝生日   
  39.     UILabel *birthDayLab = [[UILabel alloc] initWithFrame:CGRectMake(230, 40, 80, 20)];  
  40.     [birthDayLab setText:@", 4歲3個月"];  
  41.     [birthDayLab setTextColor:[UIColor blackColor]];  
  42.     [birthDayLab setFont:[UIFont systemFontOfSize:14]];  
  43.     [birthDayLab setBackgroundColor:[UIColor clearColor]];  
  44.     [headView addSubview:birthDayLab];  
  45.       
  46.     [headView release];  
  47. }  
#pragma mark addHeadView
- (void)addHeadView
{
    //頭像背景設置
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 84)];
    [headView setBackgroundColor:[UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f]];
    
    //按鈕方式添加左側用頭像
    UIButton *headBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 64, 64)];
    [headBtn setBackgroundImage:[UIImage imageNamed:@"Baby_head.png"] forState:UIControlStateNormal];
    headBtn.layer.cornerRadius = 8.0;
    headBtn.layer.masksToBounds = YES;
    [headView addSubview:headBtn];
    [headBtn release];
    [self.view addSubview:headView];
    
    //用戶名
    UILabel *unameLab = [[UILabel alloc] initWithFrame:CGRectMake(89, 15, 200, 20)];
    [unameLab setText:@"balbaba"];
    [unameLab setTextColor:[UIColor blackColor]];
    [unameLab setFont:[UIFont boldSystemFontOfSize:16]];
    [unameLab setBackgroundColor:[UIColor clearColor]];
    [headView addSubview:unameLab];
    
    //寶貝頭像小圖
    UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(89, 38, 24, 24)];
    [iconView setImage:[UIImage imageNamed:@"Baby_gender_boy.png"]];    
    [headView addSubview:iconView];
    
    //寶貝暱稱
    UILabel *nicknameLab = [[UILabel alloc] initWithFrame:CGRectMake(120, 40, 120, 20)];
    [nicknameLab setText:@"寶貝qgggfgghhjjjk"];
    [nicknameLab setTextColor:[UIColor blackColor]];
    [nicknameLab setFont:[UIFont systemFontOfSize:14]];
    [nicknameLab setBackgroundColor:[UIColor clearColor]];
    [headView addSubview:nicknameLab];
    
    //寶貝生日
    UILabel *birthDayLab = [[UILabel alloc] initWithFrame:CGRectMake(230, 40, 80, 20)];
    [birthDayLab setText:@", 4歲3個月"];
    [birthDayLab setTextColor:[UIColor blackColor]];
    [birthDayLab setFont:[UIFont systemFontOfSize:14]];
    [birthDayLab setBackgroundColor:[UIColor clearColor]];
    [headView addSubview:birthDayLab];
    
    [headView release];
}


分段表格視圖實現代碼以下:

 

 

  1. #pragma mark addTableView   
  2. - (void)addTableView  
  3. {  
  4.     _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 84, 320, 416) style:UITableViewStylePlain];  
  5.     [_tableView setDelegate:self];  
  6.     [_tableView setDataSource:self];  
  7.       
  8.     //清除分隔線   
  9.     //_tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;   
  10.     [self.view addSubview:_tableView];  
  11. }  
  12.   
  13. //代理-每一個行的Cell   
  14. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  15. {  
  16.       
  17.     NSString *iden = [NSString stringWithFormat:@"_ucenterCell_%d", 1];  
  18.       
  19.     UcenterCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];  
  20.       
  21.     if (cell == nil) {  
  22.         cell = [[[UcenterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden] autorelease];  
  23.     }  
  24.       
  25.     //cell.selectionStyle = UITableViewCellSelectionStyleNone;   
  26.     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;      
  27.       
  28.     NSDictionary *dic = [[[_dataList objectAtIndex:indexPath.section] objectForKey:@"subs"] objectAtIndex:indexPath.row];      
  29.     [cell setValueForDictionary:dic];  
  30.       
  31.     return cell;  
  32. }  
  33.   
  34. //多少個段   
  35. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView  
  36. {  
  37.     return [_dataList count];  
  38. }  
  39.   
  40. //段的高度   
  41. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section  
  42. {  
  43.     return 22;  
  44. }  
  45.   
  46. //設置每段顯示Title   
  47. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  
  48. {  
  49.     return [[[[_dataList objectAtIndex:section] objectForKey:@"subs"] objectAtIndex:0] objectForKey:@"section"];  
  50. }  
  51.   
  52. //代理-每段有多少行   
  53. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
  54. {  
  55.     return [[[_dataList objectAtIndex:section] objectForKey:@"subs"] count];  
  56. }  
  57.   
  58. //代理-計算每一個行的高度   
  59. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
  60. {  
  61.     return 44.0f;  
  62. }  
  63.   
  64. //代理-選擇行的觸發事件   
  65. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  66. {  
  67.     [tableView deselectRowAtIndexPath:indexPath animated:YES];  
  68.       
  69.     //點擊推出頁面   
  70.     DetailViewController *rvc = [[DetailViewController alloc] init];  
  71.     [self.navigationController pushViewController:rvc animated:YES];  
  72.     [rvc release];  
  73. }  
#pragma mark addTableView
- (void)addTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 84, 320, 416) style:UITableViewStylePlain];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    
    //清除分隔線
    //_tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
}

//代理-每一個行的Cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSString *iden = [NSString stringWithFormat:@"_ucenterCell_%d", 1];
    
    UcenterCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    
    if (cell == nil) {
        cell = [[[UcenterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden] autorelease];
    }
    
    //cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;    
    
    NSDictionary *dic = [[[_dataList objectAtIndex:indexPath.section] objectForKey:@"subs"] objectAtIndex:indexPath.row];    
    [cell setValueForDictionary:dic];
    
    return cell;
}

//多少個段
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_dataList count];
}

//段的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 22;
}

//設置每段顯示Title
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[[[_dataList objectAtIndex:section] objectForKey:@"subs"] objectAtIndex:0] objectForKey:@"section"];
}

//代理-每段有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[[_dataList objectAtIndex:section] objectForKey:@"subs"] count];
}

//代理-計算每一個行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

//代理-選擇行的觸發事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //點擊推出頁面
    DetailViewController *rvc = [[DetailViewController alloc] init];
    [self.navigationController pushViewController:rvc animated:YES];
    [rvc release];
}

 

 

注:

    一、註冊、登陸功能主要是鍛練對鍵盤和輸入框UITextField、UISegment及UIPickerView的熟練使用

    二、在註冊、登陸時頂部導航左、中、右相關的"返回" 、"註冊"、"完成"等按鈕儘可能直接使用系統的的相似下面代碼

 

  1. [self.navigationItem setLeftBarButtonItem:navBarBack];  
  2.   
  3.  self.navigationItem.rightBarButtonItem = navBarFinish;  
  4.   
  5.  [self.navigationItem.titleView addSubview:segment];  
 [self.navigationItem setLeftBarButtonItem:navBarBack];

  self.navigationItem.rightBarButtonItem = navBarFinish;

  [self.navigationItem.titleView addSubview:segment];

在各個ViewController之間切換和控制。

相關文章
相關標籤/搜索