一,效果图。

二,工程图。

三,代码。

RegisViewController.h

#import <UIKit/UIKit.h>

@interface RegisViewController : UIViewController

@end

RegisViewController.m

//注册页面
#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

#import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController

@end

LoginViewController.m

//登陆页面
#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];
}
 
 

【代码笔记】iOS-账号,密码记住的更多相关文章

  1. 【代码笔记】iOS-给密码进行加密

    一,工程图. 二,代码. #import "ViewController.h" #import "Base64CodeByteFunc.h" @interfac ...

  2. 通过游戏学python 3.6 第一季 第五章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆 可复制直接使用 娱乐 可封装 函数

    #猜数字--核心代码--猜测次数--随机函数和屏蔽错误代码---优化代码及注释--账号密码登陆 #!usr/bin/env python #-*-coding:utf-8-*- #QQ12411129 ...

  3. C# ASP.NET MVC:使用Cookie记住账号密码

    MVC记住账号密码 使用cookie操作 前端: <div> 用户名:<input type="text" id="UserName" val ...

  4. 利用SharedPreferences完成记住账号密码的功能

    利用SharedPreferences完成记住账号密码的功能 效果图: 记住密码后,再次登录就会出现账号密码,否则没有. 分析: SharedPreferences可将数据存储到本地的配置文件中 Sh ...

  5. css 修改placeholder字体颜色字体大小 修改input记住账号密码后的默认背景色

     壹 ❀ 引 本来这个阶段的项目页面都是给实习生妹子做的,我只用写写功能接接数据,但这两天妹子要忙翻译,这个工作阶段也快结束了导致有点慌,只能自己把剩余的几个小页面给写了. 那么做页面的过程中,UI也 ...

  6. struts2的记住账号密码的登录设计

    一个简单的基于struts2的登录功能,实现的额外功能有记住账号密码,登录错误提示.这里写上我在设计时的思路流程,希望大家能给点建设性的意见,帮助我改善设计. 登录功能的制作,首先将jsp界面搭建出来 ...

  7. cocos2d JS 本地缓存存储登陆记住账号密码->相当于C++中的UserDefault

    在cocos-js 3.0以上的版本中,当我们用到本地存储的时候,发现以前用到的UserDefault在JS中并没有导出,而是换成了LocalStorage. 在LocalStorage.h文件中我们 ...

  8. git小乌龟工具TortoiseGit记住你的账号密码

    在使用TortoiseGit的过程中,发下每次push或者pull都要重复输入账号密码,非常麻烦 怎么设置记住密码 在[系统盘]:\Users[你的用户名](比如C:\User\Administrat ...

  9. Linux让git记住账号密码

    Linux让git记住账号密码 ——IT唐伯虎 摘要: Linux让git记住账号密码. 1.进入根目录,指令:cd / 2.创建记录账号密码的文件,指令:touch .git-credentials ...

  10. 如何让git小乌龟工具TortoiseGit记住你的账号密码

    在使用小乌龟的过程中,发下每次push或者pull都要重复输入账号密码,非常麻烦. 如果能记住账号密码就好了,这样就省去了时间. 怎么设置记住密码 在[系统盘]:\Users[你的用户名]下面,有一个 ...

随机推荐

  1. Asp.Net跨平台:Ubuntu14.0+Mono+Jexus+Asp.Net

    Asp.Net跨平台的文章园子里有很多,这里给自己搭建的情况做一下总结,方便以后查看. 参考网站:   http://www.linuxdot.net/(Linux DotNET大本营 )  http ...

  2. 虚拟机体验之 KVM 篇

    在上一篇中,我展示了虚拟机软件 QEMU 的使用.效果及其性能,同时也分析了不同用户对虚拟机的不同追求.但是不管是桌面用户还是企业级用户,对虚拟机软件的追求有一点是共同的,那就是性能.QEMU 是一个 ...

  3. CanvasWebgl项目介绍

    CanvasWebgl 介绍 CanvasWebgl 是一个基于webgl 开发的2d绘图框架,使用TypeScript开发   CanvasWebgl的功能,是在屏幕空间 或者 3D空间产生一个画布 ...

  4. C# 面向对象基础

    面向对象编程OOP(Object-Oriented Programming) 类和对象 类是对象的定义,对象是类的实现. [属性集信息] [类修饰符] class 类名 [:类基] //定义类的语法格 ...

  5. PHP安全之Web攻击

    一.SQL注入攻击(SQL Injection) 攻击者把SQL命令插入到Web表单的输入域或页面请求的字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响)动态 ...

  6. idea怎么设置自己的名字和时间

    1.直接修改idea64.exe.vmoptions 里面添加上 -Duser.name=yourname 重启即可生效 1.file - settings-Editor- File and Code ...

  7. nginx+php 在windows下的简单配置安装

    开始前的准备 PHP安装包下载:http://windows.php.net/downloads/releases/php-5.5.14-Win32-VC11-x86.zip Nginx 下载地址:h ...

  8. PHP 面向对象编程和设计模式 (4/5) - 异常的定义、扩展及捕获

    PHP高级程序设计 学习笔记 2014.06.12 异常经常被用来处理一些在程序正常执行中遇到的各种类型的错误.比如做数据库链接时,你就要处理数据库连接失败的情况.使用异常可以提高我们程序的容错特性, ...

  9. pixi.js webgl库

    分析pixi源码,刚搭建环境gulp+webpack,目前正在看... https://github.com/JsAaron/webgl-demo

  10. OpenCASCADE Data Exchange - 3D PDF

    OpenCASCADE Data Exchange - 3D PDF eryar@163.com Abstract. Today most 3D engineering model data are ...