第三步
实现基础页面,如下图

声明变量,遵守指纹验证控件的协议
@interface ViewController ()<WJTouchIDDelegate>
/** NoticeLabel */
@property (nonatomic,strong) UILabel *label;
/** UISwitch */
@property (nonatomic,strong) UISwitch *touchIDSwitch;
@property (nonatomic, strong) WJTouchID *touchID;
@end
懒加载
-(UISwitch *)touchIDSwitch
{
if (!_touchIDSwitch)
{
self.touchIDSwitch = [[UISwitch alloc]init];
}
return _touchIDSwitch;
}
添加子控件
-(void)setSubViews
{
self.label = [[UILabel alloc]init];
[self.view addSubview:self.label];
[self.label setFrame:ZLRect(0, 100/667, 1, 20/667)];
[self.label setText:@"指纹解锁"];
[self.label setTextAlignment:NSTextAlignmentCenter];
[self.label setFont:[UIFont systemFontOfSize:ZCFont(18/375)]];
self.touchIDSwitch = [[UISwitch alloc]init];
[self.touchIDSwitch setFrame:ZLRect(160/375, 200/667, 50/375, 28/667)];
[self.view addSubview:self.touchIDSwitch];
if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"TouchID"] isEqualToString:@"1"])
{
self.touchIDSwitch.on = YES;
}else
{
self.touchIDSwitch.on = NO;
}
[self.touchIDSwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
}
这里要说一下
[[[NSUserDefaults standardUserDefaults]objectForKey:@"TouchID"] isEqualToString:@"1"]
这个我是将是否设置了指纹验证存到了本地,因为当你进入设置页面的时候,必须知道你本机是否已经设置了指纹验证,这里存在着设置与未设置的一个页面UI差别,我这边就是用switch的开关来打开关闭指纹验证,也是用开关状态来表示指纹验证是否打开。
第四步
在viewdidload方法中调用设置子控件的方法,并且实现开关切换的方法。
- (void)viewDidLoad {
[super viewDidLoad];
[self setSubViews];
}
切换方法里呢,就是需要调用者会问验证,一般软件设置指纹验证的时候都会要求你先验证一下子,我在这里设置成只要你开或关闭都需要验证一下。
-(void)changeSwitch:(id)sender
{
NSLog(@"------changeSwitch-------");
WJTouchID *touchid = [[WJTouchID alloc]init];
[touchid startWJTouchIDWithMessage:WJNotice(@"自定义信息", @"The Custom Message") fallbackTitle:WJNotice(@"", @"Fallback Title") delegate:self];
self.touchID = touchid;
}










