iOS簡(jiǎn)單登錄LoginViewController、注冊(cè)RegisterViewController等功能實(shí)現(xiàn)方法
一、個(gè)人中心未登錄
方法:
加判斷登錄狀態(tài)直接打開(kāi)個(gè)人中心頁(yè)面4,否則出現(xiàn)上面引導(dǎo)登錄或注冊(cè)入口顯示
代碼如下:
#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]; //登錄、注冊(cè)提示 UILabel *loginLab = [[UILabel alloc] initWithFrame:CGRectMake(55, 43, 199, 80)]; [loginLab setText:@"登錄工程師爸爸,網(wǎng)站收藏、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]; //注冊(cè) 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]; }
二、登錄
頂部導(dǎo)航代碼:
#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]; //右側(cè)完成 UIBarButtonItem *navBarFinish = [[UIBarButtonItem alloc] initWithTitle:@"注冊(cè)" style:UIBarButtonItemStyleDone target:self action:@selector(btnClick:)]; navBarFinish.tag = 102; self.navigationItem.rightBarButtonItem = navBarFinish; [navBarFinish release]; }
登錄界面代碼實(shí)現(xiàn)如下:
#pragma mark addView //創(chuàng)建輸入框 - (void)addInput { //基本參數(shù)定義 CGFloat padx = 80.0f; _vFrame = CGRectMake(10, 14, 300, 80); UIFont *lpFont = [UIFont boldSystemFontOfSize:16]; //郵箱和密碼背景顏色設(shè)置 _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]; //編輯時(shí)會(huì)出現(xiàn)個(gè)修改X [_email setTag:101]; [_email setReturnKeyType:UIReturnKeyNext]; //鍵盤(pán)下一步Next [_email setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關(guān)閉首字母大寫(xiě) [_email setAutocorrectionType:UITextAutocorrectionTypeNo]; [_email becomeFirstResponder]; //默認(rèn)打開(kāi)鍵盤(pán) [_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]; //關(guān)閉首字母大寫(xiě) [_passwd setReturnKeyType:UIReturnKeyDone]; //完成 [_passwd setSecureTextEntry:YES]; //驗(yàn)證 [_passwd setDelegate:self]; [_passwd setTag:102]; [_passwd setTextColor:[UIColor grayColor]]; [_passwd setFont:lpFont]; [_passwd setText:@"" [_view addSubview:_passwd]; }
三、注冊(cè)
頂部導(dǎo)航控制,代碼實(shí)現(xiàn)如下:
- (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]; //設(shè)標(biāo)題 [self setXDTitle:@"注冊(cè)" pageName:@""]; //添加返回按鈕 [self addInputOne]; //注冊(cè)第一步 }else{ [self setXDTitle:@"寶貝信息設(shè)置" 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]; //右側(cè)完成 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]; } }
注冊(cè)分兩步:
第一步基本信息注冊(cè),代碼如下
//創(chuàng)建輸入框 - (void)addInputOne { //基本參數(shù)定義 CGFloat padx = 95.0f; _vFrame = CGRectMake(10, 14, 300, 125); UIFont *lpFont = [UIFont boldSystemFontOfSize:16]; //郵箱和密碼背景顏色設(shè)置 _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]; //鍵盤(pán)下一步Next [_uname setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關(guān)閉首字母大寫(xiě) [_uname setAutocorrectionType:UITextAutocorrectionTypeNo]; [_uname setReturnKeyType:UIReturnKeyNext]; //下一個(gè)Passwd [_uname becomeFirstResponder]; //默認(rèn)打開(kāi)鍵盤(pán) [_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]; //關(guān)閉首字母大寫(xiě) [_passwd setReturnKeyType:UIReturnKeyNext]; //下一個(gè)Email [_passwd setSecureTextEntry:YES]; //驗(yàn)證 [_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]; //鍵盤(pán)下一步Next [_email setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關(guān)閉首字母大寫(xiě) [_email setAutocorrectionType:UITextAutocorrectionTypeNo]; [_email setFont:[UIFont systemFontOfSize:17]]; [_email setDelegate:self]; [_email setPlaceholder:@"devdiy@example.com"]; [_email setText:@""]; [_email setHighlighted:YES]; [_view addSubview:_email]; }
第二步完善資源輸入,代碼實(shí)現(xiàn)如下:
//創(chuàng)建輸入框 - (void)addInputTow { //基本參數(shù)定義 CGFloat padx = 100.0f; _vFrame = CGRectMake(10, 10, 300, 125); UIFont *lpFont = [UIFont boldSystemFontOfSize:16]; //寶貝小名、寶貝性別、寶貝生日背景顏色設(shè)置 _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]; //鍵盤(pán)下一步Next [_nickname setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //關(guān)閉首字母大寫(xiě) [_nickname setAutocorrectionType:UITextAutocorrectionTypeNo]; [_nickname setReturnKeyType:UIReturnKeyNext]; //下一個(gè)寶貝性別 [_nickname becomeFirstResponder]; //默認(rèn)打開(kāi)鍵盤(pán) [_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:@"推薦引擎會(huì)根據(jù)孩子信息進(jìn)行個(gè)性推薦"]; [_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"]; //將當(dāng)前生日時(shí)間設(shè)置到日期輪軸上 _datePicker.date = [dateFormatter dateFromString:_birthDay.titleLabel.text]; //設(shè)置為中文顯示 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]; }
四、注冊(cè),登錄成功后直接進(jìn)入個(gè)人中心頁(yè)
頂部界面代碼實(shí)現(xiàn)如下:
#pragma mark addHeadView - (void)addHeadView { //頭像背景設(shè)置 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]]; //按鈕方式添加左側(cè)用頭像 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個(gè)月"]; [birthDayLab setTextColor:[UIColor blackColor]]; [birthDayLab setFont:[UIFont systemFontOfSize:14]]; [birthDayLab setBackgroundColor:[UIColor clearColor]]; [headView addSubview:birthDayLab]; [headView release]; }
分段表格視圖實(shí)現(xiàn)代碼如下:
#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]; } //代理-每個(gè)行的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; } //多少個(gè)段 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [_dataList count]; } //段的高度 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 22; } //設(shè)置每段顯示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]; } //代理-計(jì)算每個(gè)行的高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 44.0f; } //代理-選擇行的觸發(fā)事件 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; //點(diǎn)擊推出頁(yè)面 DetailViewController *rvc = [[DetailViewController alloc] init]; [self.navigationController pushViewController:rvc animated:YES]; [rvc release]; }
注:
1、注冊(cè)、登錄功能主要是鍛練對(duì)鍵盤(pán)和輸入框UITextField、UISegment及UIPickerView的熟練使用
2、在注冊(cè)、登錄時(shí)頂部導(dǎo)航左、中、右相關(guān)的"返回" 、"注冊(cè)"、"完成"等按鈕盡量直接使用系統(tǒng)的的類似下面代碼
[self.navigationItem setLeftBarButtonItem:navBarBack]; self.navigationItem.rightBarButtonItem = navBarFinish; [self.navigationItem.titleView addSubview:segment];
在各個(gè)ViewController之間切換和控制。
至此完整的用戶注冊(cè)、登錄、進(jìn)入中心頁(yè)界面實(shí)現(xiàn)就完成了,結(jié)合上面的代碼實(shí)現(xiàn)其它IOS項(xiàng)目App應(yīng)用的功能和流程上大同小異,需要我們自己根據(jù)實(shí)際產(chǎn)品業(yè)務(wù)的要求
做出調(diào)整,希望對(duì)網(wǎng)友有幫助。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- iOS+PHP注冊(cè)登錄系統(tǒng) PHP部分(上)
- IOS開(kāi)發(fā)用戶登錄注冊(cè)模塊所遇到的問(wèn)題
- Laravel實(shí)現(xiàn)用戶注冊(cè)和登錄
- ThinkPHP之用戶注冊(cè)登錄留言完整實(shí)例
- JavaWeb實(shí)現(xiàn)用戶登錄注冊(cè)功能實(shí)例代碼(基于Servlet+JSP+JavaBean模式)
- ASP.NET登錄注冊(cè)頁(yè)面實(shí)現(xiàn)
- 基于jquery+thickbox仿校內(nèi)登錄注冊(cè)框
- JSP實(shí)現(xiàn)用戶登錄、注冊(cè)和退出功能
- 用Python實(shí)現(xiàn)web端用戶登錄和注冊(cè)功能的教程
- 圖文演示Flash+ASP實(shí)現(xiàn)用戶登錄/注冊(cè)程序
- iOS+PHP注冊(cè)登錄系統(tǒng) iOS部分(下)
相關(guān)文章
iOS開(kāi)發(fā)中UIPopoverController的使用詳解
這篇文章主要介紹了iOS開(kāi)發(fā)中UIPopoverController的使用,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-11-11Unity移動(dòng)端的復(fù)制要這么寫(xiě)示例代碼
這篇文章主要給大家介紹了關(guān)于Unity移動(dòng)端的復(fù)制的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08iOS開(kāi)發(fā)檢測(cè)是否開(kāi)啟定位、是否允許消息推送等權(quán)限的實(shí)例
下面小編就為大家分享一篇iOS開(kāi)發(fā)檢測(cè)是否開(kāi)啟定位、是否允許消息推送等權(quán)限的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01iOS tableview實(shí)現(xiàn)簡(jiǎn)單搜索功能
這篇文章主要為大家詳細(xì)介紹了iOS tableview實(shí)現(xiàn)簡(jiǎn)單搜索功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11iOS視頻壓縮存儲(chǔ)至本地并上傳至服務(wù)器實(shí)例代碼
本篇文章主要介紹了iOS視頻壓縮存儲(chǔ)至本地并上傳至服務(wù)器實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04iOS應(yīng)用設(shè)計(jì)模式開(kāi)發(fā)中職責(zé)鏈(責(zé)任鏈)模式的實(shí)現(xiàn)解析
這篇文章主要介紹了iOS應(yīng)用設(shè)計(jì)模式開(kāi)發(fā)中職責(zé)鏈模式的相關(guān)實(shí)現(xiàn)解析,示例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-03-03