登陆界面的搭建

一、个人中心未登录


方法:

      加判断登录状态直接打开个人中心页面4,否则出现上面引导登录或注册入口显示

代码如下:

    

[cpp]  view plain copy
  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:@"[email protected]"] 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:@"[email protected]"] forState:UIControlStateHighlighted];  
  34.     [registerBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];  
  35.     [registerBtn setTag:102];  
  36.     [self.view addSubview:registerBtn];  
  37.     [registerBtn release];  
  38. }  

二、登录

顶部导航代码:

[cpp]  view plain copy
  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:@"[email protected]"] 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. }  

登录界面代码实现如下:

[cpp]  view plain copy
  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. }  
三、注册


顶部导航控制,代码实现如下:

[cpp]  view plain copy
  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:@"[email protected]"] 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:@"[email protected]"] 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. }  

注册分两步:

第一步基本信息注册,代码如下

[cpp]  view plain copy
  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:@"[email protected]"];  
  104.     [_email setText:@""];  
  105.     [_email setHighlighted:YES];  
  106.     [_view addSubview:_email];  
  107. }  
第二步完善资源输入,代码实现如下:

[cpp]  view plain copy
  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. }  

三、注册,登录成功后直接进入个人中心页


顶部界面代码实现如下:

[cpp]  view plain copy
  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. }  

分段表格视图实现代码如下:

[cpp]  view plain copy
  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. }  

注:

    1、注册、登录功能主要是锻练对键盘和输入框UITextField、UISegment及UIPickerView的熟练使用

    2、在注册、登录时顶部导航左、中、右相关的"返回" 、"注册"、"完成"等按钮尽量直接使用系统的的类似下面代码

猜你喜欢

转载自blog.csdn.net/woruosuifenglang/article/details/49908599