鸿 网 互 联 www.68idc.cn

IOS开发简单登录LoginViewController、注册RegisterViewControll

来源:互联网 作者:佚名 时间:2015-10-25 11:17
这里演示了加密文本,利用特定字符来定位位置sockdata=PHIDOHBBNIEFMNDIBJLENNEBBODILAEAPMIHHKMKBOKILJOJHGPDDBEOPMCEMLAPJNFDLOJCPHEAMEDNPINODFMBMLFPFHLLGBN

一、个人中心未登录

IOS开发简单登录LoginViewController、注册RegisterViewControll


方法:

      加判断登录状态直接打开个人中心页面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、注册RegisterViewControll

顶部导航代码:

#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]; } 三、注册
网友评论
<