服务器之家

服务器之家 > 正文

iOS实现账号、密码记住功能

时间:2021-03-09 16:00     来源/作者:弦外雨

本文实例为大家分享了android九宫格图片展示的具体代码,供大家参考,具体内容如下

一、效果图

iOS实现账号、密码记住功能

iOS实现账号、密码记住功能

二、工程图

iOS实现账号、密码记住功能

三、代码

regisviewcontroller.h

?
1
2
3
4
5
#import <uikit/uikit.h>
 
@interface regisviewcontroller : uiviewcontroller
 
@end

 regisviewcontroller.m

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//注册页面
#import "regisviewcontroller.h"
#import "loginviewcontroller.h"
 
@interface regisviewcontroller ()
{
  uitextfield *accountfield;
  uitextfield *passfield;
}
 
@end
 
@implementation regisviewcontroller
 
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil
{
  self = [super initwithnibname:nibnameornil bundle:nibbundleornil];
  if (self) {
    // custom initialization
  }
  return self;
}
 
- (void)viewdidload
{
  [super viewdidload];
  // do any additional setup after loading the view.
  
  self.title=@"注册";
  
  [self initview];
  
}
-(void)initview
{
  accountfield=[[uitextfield alloc]initwithframe:cgrectmake(50, 100, 200, 40)];
  [accountfield setbackgroundcolor:[uicolor redcolor]];
  [accountfield setplaceholder:@"请输入账号"];
  [accountfield setkeyboardtype:uikeyboardtypenumberpad];
  [accountfield setclearscontextbeforedrawing:yes];
  [self.view addsubview:accountfield];
  
  
  passfield=[[uitextfield alloc]initwithframe:cgrectmake(50, 160, 200, 40)];
  [passfield setbackgroundcolor:[uicolor redcolor]];
  [passfield setplaceholder:@"请输入密码"];
  [passfield setkeyboardtype:uikeyboardtypenumberpad];
  [passfield setclearscontextbeforedrawing:yes];
  [self.view addsubview:passfield];
  
  
  uibutton *registebut=[uibutton buttonwithtype:uibuttontyperoundedrect];
  registebut.backgroundcolor=[uicolor greencolor];
  registebut.frame=cgrectmake(70, 220, 100, 40);
  [registebut settitle:@"注册" forstate:uicontrolstatenormal];
  [registebut addtarget:self action:@selector(resis) forcontrolevents:uicontroleventtouchupinside];
  [self.view addsubview:registebut];
 
}
 
//注册的时候,将账号,密码保存到本地。
-(void)resis
{
 
  nsuserdefaults *defaut=[nsuserdefaults standarduserdefaults];
  [defaut setobject:accountfield.text forkey:@"account"];
  [defaut setobject:passfield.text forkey:@"password"];
  [defaut synchronize];
  
  loginviewcontroller *login=[[loginviewcontroller alloc]init];
  [self.navigationcontroller pushviewcontroller:login animated:yes];
    
  
}
- (void)didreceivememorywarning
{
  [super didreceivememorywarning];
  // dispose of any resources that can be recreated.
}

loginviewcontroller.h

?
1
2
3
4
5
#import <uikit/uikit.h>
 
@interface loginviewcontroller : uiviewcontroller
 
@end

 loginviewcontroller.m

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//登陆页面
#import "loginviewcontroller.h"
 
@class regisviewcontroller;
@interface loginviewcontroller ()
{
  uitextfield *accountfield;
  uitextfield *passfield;
}
@end
 
@implementation loginviewcontroller
 
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil
{
  self = [super initwithnibname:nibnameornil bundle:nibbundleornil];
  if (self) {
    // custom initialization
  }
  return self;
}
 
- (void)viewdidload
{
  [super viewdidload];
  // do any additional setup after loading the view.
  self.title=@"登陆";
  
  [self initview];
  
}
-(void)initview
{
  accountfield=[[uitextfield alloc]initwithframe:cgrectmake(50, 100, 200, 40)];
  [accountfield setbackgroundcolor:[uicolor redcolor]];
  [accountfield setkeyboardtype:uikeyboardtypenumberpad];
  [accountfield setclearscontextbeforedrawing:yes];
  [accountfield settext:[[nsuserdefaults standarduserdefaults] objectforkey:@"account"]];
  [self.view addsubview:accountfield];
  
  
  passfield=[[uitextfield alloc]initwithframe:cgrectmake(50, 160, 200, 40)];
  [passfield setbackgroundcolor:[uicolor redcolor]];
  [passfield settext:[[nsuserdefaults standarduserdefaults] objectforkey:@"password"]];
  [passfield setkeyboardtype:uikeyboardtypenumberpad];
  [passfield setclearscontextbeforedrawing:yes];
  [self.view addsubview:passfield];
  
  
  uibutton *loginbut=[uibutton buttonwithtype:uibuttontyperoundedrect];
  loginbut.backgroundcolor=[uicolor greencolor];
  loginbut.frame=cgrectmake(70, 220, 100, 40);
  [loginbut settitle:@"登陆" forstate:uicontrolstatenormal];
  [loginbut addtarget:self action:@selector(login) forcontrolevents:uicontroleventtouchupinside];
  [self.view addsubview:loginbut];
  
  
}
-(void)login
{
  [self.navigationcontroller popviewcontrolleranimated:yes];
}

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

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部