一.ViewController.h中代码
//// ViewController.h// 归档登陆//// Created by 非凡程序员 on 15/6/12.// Copyright (c) 2015年 wzhen. All rights reserved.//#import@interface ViewController : UIViewController@property (weak, nonatomic) IBOutlet UITextField *name;@property (weak, nonatomic) IBOutlet UITextField *passworld;@property (weak, nonatomic) IBOutlet UILabel *reminder;- (IBAction)enter:(id)sender;@property (weak, nonatomic) IBOutlet UIButton *card;@end
二.ViewController.m中代码
//// ViewController.m// 归档登陆//// Created by 非凡程序员 on 15/6/12.// Copyright (c) 2015年 wzhen. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (IBAction)enter:(id)sender { NSMutableData *mudate=[[NSMutableData alloc]init];//可变文件留,分配内存 NSKeyedArchiver *archiver=[[NSKeyedArchiver alloc]initForWritingWithMutableData:mudate]; NSString *setname=@"wangzhen"; NSString *setpassworld=@"888888"; [archiver encodeObject:setname forKey:@"setname"]; [archiver encodeObject:setpassworld forKey:@"setpassworld"]; [archiver finishEncoding]; [mudate writeToFile:@"/Users/feifanchengxuyuan/Desktop/enter.txt" atomically:YES]; NSKeyedUnarchiver *unarchiver=[[NSKeyedUnarchiver alloc]initForReadingWithData:mudate]; NSString *getname=[unarchiver decodeObjectForKey:@"setname"]; NSString *getpassworld=[unarchiver decodeObjectForKey:@"setpassworld"]; if ([_name.text isEqualToString:getname]) { if ([_passworld.text isEqualToString:getpassworld]) { [_reminder setText:@"登陆成功"]; NSLog(@"登录成功"); // [_card setTitle:@"登录成功,进入下一个链接页面" forState:UIControlStateNormal]; } else{ [_reminder setText:@"抱歉,您的登录名和密码不匹配"]; } } else{ [_reminder setText:@"抱歉,您的登录名不存在"]; } NSLog(@"name:%@,passworld:%@",getname,getpassworld); }@end
三.隐藏显示的密码
勾选右侧中的Secure Text Entry