欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-18 22:49:34
一、个人中心未登录 方法:       加判断登录状态直接打开个人中心页面4,否则出现上面引导登录或注册入口显示...

一、个人中心未登录

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

二、登录

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

顶部导航代码:

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

三、注册

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

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

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

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

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

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

顶部界面代码实现如下:

#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应用的功能和流程上大同小异,需要我们自己根据实际产品业务的要求

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

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

上一篇:

下一篇: