iOS简单登录LoginViewController、注册RegisterViewController等功能实现方法

一、个人中心未登录

方法:

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

代码如下:

#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];
}

二、登录

顶部导航代码:

#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];
}

登录界面代码实现如下:

#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];
}

三、注册

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

- (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];
 }
}

注册分两步:

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

//创建输入框
- (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];
}

第二步完善资源输入,代码实现如下:

//创建输入框
- (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];
}

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

顶部界面代码实现如下:

#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];
}

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

#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];
}

注:

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

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

 [self.navigationItem setLeftBarButtonItem:navBarBack];
 self.navigationItem.rightBarButtonItem = navBarFinish;
 [self.navigationItem.titleView addSubview:segment];

在各个ViewController之间切换和控制。

至此完整的用户注册、登录、进入中心页界面实现就完成了,结合上面的代码实现其它IOS项目App应用的功能和流程上大同小异,需要我们自己根据实际产品业务的要求

做出调整,希望对网友有帮助。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • JSP实现用户登录、注册和退出功能

    本文讲述使用JSP实现用户登录,包括用户登录.注册和退出功能等. 1.系统用例图 2.页面流程图 3.数据库设计 本例使用oracle数据库 创建用户表 包括id,username,password和email,共4个字段 -- Create table create table P_USER ( id VARCHAR2(50) not null, username VARCHAR2(20), password VARCHAR2(20), email VARCHAR2(50) ) tablesp

  • 图文演示Flash+ASP实现用户登录/注册程序第1/2页

    Flash一帧可以完成.asp也可以一个文件完成,这里我将用户登录和用户注册分为两步做,方便大家理解,Flash分两帧,asp分两个文件. 准备: Flash8 , IIS ,Miscrosoft Access 2003; 开始: 数据库中: 用设计视图新建一个名为 UserTable 的表,三个字段分别为 id 为自动编号,username为文本,password为文本;输入一条数据 username 和 password 都为chooseflash; 如图: Flash中: 新建文件命名为l

  • Laravel实现用户注册和登录

    Laravel身为最优雅的PHP框架,很多学习PHP的小伙伴造就对Laravel垂涎欲滴.今天就来实现你的愿望,让我们一起从零开始,利用Laravel实现Web应用最常见的注册和登录功能!所有的课程源码已放在Github上:laravel-start. Race Start ! 首先我们来明确一下我们这个课程需要的东西: Laravel 4.2 Bootstrap 3.3 Laravel就是我们关心的核心部分,Bootstrap用来快速设置一些前端的CSS样式. 1.安装Laravel 简单说明

  • iOS+PHP注册登录系统 iOS部分(下)

    接着上篇<iOS+PHP注册登录系统 PHP部分(上)>进行学习 3.iOS部分 上一次我们写完了数据库部分和PHP部分这次我们来完成iOS部分. 首先先在storyboard中一阵狂拖,弄成如下图. 可以先在text Field中输入用户名和密码 方便以后调试. 3.1登录部分代码 创建一个新的UIViewController 名为registViewController(用于注册用户,ViewController用于登录). 在ViewController.h中importregistVi

  • ThinkPHP之用户注册登录留言完整实例

    本文以实例形式讲述ThinkPHP实现的包括用户的注册.登录以及留言等功能,这里需要大家注意的是,在存在用户模型的情况下实例化一个用户类的时候使用D方法来实现.   UserActiion.class.php页面: <?php class UserAction extends Action{ public function add(){ $user = D("user"); $user->create(); $result = $user->add(); if($re

  • IOS开发用户登录注册模块所遇到的问题

    最近和另外一位同事负责公司登录和用户中心模块的开发工作,开发周期计划两周,减去和产品和接口的协调时间,再减去由于原型图和接口的问题,导致强迫症纠结症状高发,情绪不稳定耗费的时间,能在两周基本完成也算是个不小的奇迹了.本文就总结一下如何满足产品需要的情况下,高效开发一个登录注册模块. 1.利用继承解决界面重复性功能.通常登录注册会有一个独立的设计,而模块内部会有有相似的背景,相似的导航栏样式,相似返回和退出行为,相似的输入框,按钮样式等. 比如上面的的注册和登录模块,就有相同的返回按钮,相同的背景

  • ASP.NET登录注册页面实现

    如何利用Visual  studio 2010创建一个ASP网站? [文件]-->[新建]-->[网站]-->[ASP.Net网站]--[完成] 默认页面Default.aspx 创建以上界面: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserLogin.aspx.cs" Inherits="UserLogin" %> <

  • iOS+PHP注册登录系统 PHP部分(上)

    最后达成效果:        分析做项目的基本流程: 1.先创建数据库 2.写PHP服务端 3.写iOS用户端 1.创建数据库 我用的是wamp. 数据库名称为ioslogin,表名为users其中有3个字段user_id,user_name和user_pwd. user_id为自增长. 2.php服务端 php端我用的是EclipsePHP编写. 先创建一个配置文件config.php. <?php $DBHOST="localhost"; $DBUSER="root

  • 用Python实现web端用户登录和注册功能的教程

    用户管理是绝大部分Web网站都需要解决的问题.用户管理涉及到用户注册和登录. 用户注册相对简单,我们可以先通过API把用户注册这个功能实现了: _RE_MD5 = re.compile(r'^[0-9a-f]{32}$') @api @post('/api/users') def register_user(): i = ctx.request.input(name='', email='', password='') name = i.name.strip() email = i.email.

  • 基于jquery+thickbox仿校内登录注册框

    下面将我用thickbox和css实现校内登录(注册)框与大家分享下----->效果图如下: 方法很简单,就是用thickbox的iframe模式,将另一个页面嵌套即可,然后在这个页面里写ajax来实现相应的功能. 代码: 注册:regUser.html 复制代码 代码如下: <link type="text/css" href="css/reg.css" rel="Stylesheet" /> <script type=

  • JavaWeb实现用户登录注册功能实例代码(基于Servlet+JSP+JavaBean模式)

    下面通过通过图文并茂的方式给大家介绍JavaWeb实现用户登录注册功能实例代码,一起看看吧. 一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp负责数据显示,javabean负责封装数据. Servlet+JSP+JavaBean模式程序各个模块之间层次清晰,web开发推荐采用此种模式. 这里以一个最常用的用户登录注册程序来讲解Servlet+JS

随机推荐