TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Feb 2016 |
Maintained by i36lib.
DBGuestureLock
is an iOS drop-in class which is very easy to use. I am welcome you to make any additional useful features to DBGuestureLock to make it better. If you want to make a contribution to this project, just make a pull request. If you like this project, make a star!
DBGuestureLock
is build under iOS SDK9.2
with Xcode7.2.1(7C1002)
and pass test on travis-ci with Xcode7
and iOS SDK9.0
. You should use DBGuestureLock under ARC
.
Just add the DBGuestureButton.h
, DBGuestureButton.m
,DBGuestureLock.h
, DBGuestureLock.m
source files to your project directly.
#import "DBGuestureLock.h"
.There are two ways to use DBGuestureLock, work with delegate and work with block.
The most easy way to use, just import the DBGuestureLock.h
and type in two statements of code:
#import "DBGuestureLock.h"
@interface ViewController ()
Create a GuestureLock
object in viewDidLoad
and add it as the subview of current view:
- (void)viewDidLoad {
[super viewDidLoad];
[DBGuestureLock clearGuestureLockPassword]; //just for test
DBGuestureLock *lock = [DBGuestureLock lockOnView:self.view onPasswordSet:^(DBGuestureLock *lock, NSString *password) {
if (lock.firstTimeSetupPassword == nil) {
lock.firstTimeSetupPassword = password;
NSLog(@"varify your password");
self.label.text = @"Enter your password again:";
}
} onGetCorrectPswd:^(DBGuestureLock *lock, NSString *password) {
if (lock.firstTimeSetupPassword && ![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
lock.firstTimeSetupPassword = DBFirstTimeSetupPassword;
NSLog(@"password has been setup!");
self.label.text = @"password has been setup!";
} else {
NSLog(@"login success");
self.label.text = @"login success!";
}
} onGetIncorrectPswd:^(DBGuestureLock *lock, NSString *password) {
if (![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
NSLog(@"Error: password not equal to first setup!");
self.label.text = @"Not equal to first setup!";
} else {
NSLog(@"login failed");
self.label.text = @"login failed!";
}
}];
[self.view addSubview:lock];
[self.view setBackgroundColor:[UIColor colorWithRed:0.133 green:0.596 blue:0.933 alpha:1.00]];
}
Call the following method to set lock themes for three Button state if you need:
-(void)setupLockThemeWithLineColor:(UIColor*)lineColor lineWidth:(CGFloat)lineWidth strokeColor:(UIColor*)strokeColor strokeWidth:(CGFloat)strokeWidth circleRadius:(CGFloat)circleRadius fillColor:(UIColor*)fillColor showCenterPoint:(BOOL)showCenterPoint centerPointColor:(UIColor*)centerPointColor centerPointRadius:(CGFloat)centerPointRadius fillCenterPoint:(BOOL)fillCenterPoint onState:(DBButtonState)buttonState;
Import the DBGuestureLock.h
in your ViewController
and make your ViewController conforms to DBGuestureLockDelegate
delegate:
#import "DBGuestureLock.h"
@interface ViewController ()<DBGuestureLockDelegate>
Create a GuestureLock
object and add it to your view in viewDidLoad
method:
- (void)viewDidLoad {
[super viewDidLoad];
[DBGuestureLock clearGuestureLockPassword]; //just for test
DBGuestureLock *lock = [DBGuestureLock lockOnView:self.view delegate:self];
[self.view addSubview:lock];
[self.view setBackgroundColor:[UIColor colorWithRed:0.133 green:0.596 blue:0.933 alpha:1.00]];
}
Implement the 3 require delegate methods:
-(void)guestureLock:(DBGuestureLock *)lock didSetPassword:(NSString *)password {
// test
if (lock.firstTimeSetupPassword == nil) {
lock.firstTimeSetupPassword = password;
NSLog(@"varify your password");
self.label.text = @"Enter your password again:";
}
}
-(void)guestureLock:(DBGuestureLock *)lock didGetCorrectPswd:(NSString *)password {
// test
if (lock.firstTimeSetupPassword && ![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
lock.firstTimeSetupPassword = DBFirstTimeSetupPassword;
NSLog(@"password has been setup!");
self.label.text = @"password has been setup!";
} else {
NSLog(@"login success");
self.label.text = @"login success!";
}
}
-(void)guestureLock:(DBGuestureLock *)lock didGetIncorrectPswd:(NSString *)password {
// test
if (![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
NSLog(@"Error: password not equal to first setup!");
self.label.text = @"Not equal to first setup!";
} else {
NSLog(@"login failed");
self.label.text = @"login failed!";
}
}
Some other optional delegate methods allow you to change the style of the lock:
-(BOOL)showButtonCircleCenterPointOnState:(DBButtonState)buttonState;
-(BOOL)fillButtonCircleCenterPointOnState:(DBButtonState)buttonState;//NO for stroke, YES for fill
-(CGFloat)widthOfButtonCircleStrokeOnState:(DBButtonState)buttonState;
-(CGFloat)radiusOfButtonCircleCenterPointOnState:(DBButtonState)buttonState;
-(CGFloat)lineWidthOfGuestureOnState:(DBButtonState)buttonState;
-(UIColor *)colorOfButtonCircleStrokeOnState:(DBButtonState)buttonState;
-(UIColor *)colorForFillingButtonCircleOnState:(DBButtonState)buttonState;
-(UIColor *)colorOfButtonCircleCenterPointOnState:(DBButtonState)buttonState;
-(UIColor *)lineColorOfGuestureOnState:(DBButtonState)buttonState;
DBButtonState
include:
DBButtonStateNormal //Normal state button
DBButtonStateSelected //when button is selected
DBButtonStateIncorrect //when password is incorrect
Other class methods/property allow you to operate with the password (password is saved in UserDefaults):
+(BOOL)passwordSetupStatus;
+(void)clearGuestureLockPassword;
+(NSString *)getGuestureLockPassword;
@property (nonatomic, readonly, assign)BOOL isPasswordSetup;
This code is distributed under the terms and conditions of the MIT license.