123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- //
- // DBGuestureLockView.m
- // DBGuestureLock
- //
- // Created by DeBao.Wu on 2/27/16.
- // Email: i36.lib@gmail.com QQ: 754753371
- // Copyright © 2016 http://i36.Me/. All rights reserved.
- // Github地址: https://github.com/i36lib/DBGuestureLock/
- #import "DBGuestureLock.h"
- #import "DBGuestureButton.h"
- #define DBGuestureLockPaswd @"Me_i36_DBGuestureLock_Password"
- @interface DBGuestureLock()
- @property (nonatomic, assign)CGPoint currentPoint;
- @property (nonatomic, strong)NSMutableArray *selectedButtons;
- @property (nonatomic, assign)BOOL isPasswordSetup;
- @property (nonatomic, assign)BOOL fillCenterPoint;
- @property (nonatomic, assign)BOOL showCenterPoint;
- @property (nonatomic, assign)CGFloat lineWidth;
- @property (nonatomic, assign)CGFloat circleRadius;
- @property (nonatomic, assign)CGFloat strokeWidth;
- @property (nonatomic, assign)CGFloat centerPointRadius;
- @property (nonatomic, strong)UIColor *lineColor;
- @property (nonatomic, strong)UIColor *fillColor;
- @property (nonatomic, strong)UIColor *strokeColor;
- @property (nonatomic, strong)UIColor *centerPointColor;
- //Work with block
- @property (nonatomic, assign)BOOL fillCenterPointOnStateNormal;
- @property (nonatomic, assign)BOOL showCenterPointOnStateNormal;
- @property (nonatomic, assign)CGFloat lineWidthOnStateNormal;
- @property (nonatomic, assign)CGFloat circleRadiusOnStateNormal;
- @property (nonatomic, assign)CGFloat strokeWidthOnStateNormal;
- @property (nonatomic, assign)CGFloat centerPointRadiusOnStateNormal;
- @property (nonatomic, strong)UIColor *lineColorOnStateNormal;
- @property (nonatomic, strong)UIColor *fillColorOnStateNormal;
- @property (nonatomic, strong)UIColor *strokeColorOnStateNormal;
- @property (nonatomic, strong)UIColor *centerPointColorOnStateNormal;
- @property (nonatomic, assign)BOOL fillCenterPointOnStateSelected;
- @property (nonatomic, assign)BOOL showCenterPointOnStateSelected;
- @property (nonatomic, assign)CGFloat lineWidthOnStateSelected;
- @property (nonatomic, assign)CGFloat circleRadiusOnStateSelected;
- @property (nonatomic, assign)CGFloat strokeWidthOnStateSelected;
- @property (nonatomic, assign)CGFloat centerPointRadiusOnStateSelected;
- @property (nonatomic, strong)UIColor *lineColorOnStateSelected;
- @property (nonatomic, strong)UIColor *fillColorOnStateSelected;
- @property (nonatomic, strong)UIColor *strokeColorOnStateSelected;
- @property (nonatomic, strong)UIColor *centerPointColorOnStateSelected;
- @property (nonatomic, assign)BOOL fillCenterPointOnStateIncorrect;
- @property (nonatomic, assign)BOOL showCenterPointOnStateIncorrect;
- @property (nonatomic, assign)CGFloat lineWidthOnStateIncorrect;
- @property (nonatomic, assign)CGFloat circleRadiusOnStateIncorrect;
- @property (nonatomic, assign)CGFloat strokeWidthOnStateIncorrect;
- @property (nonatomic, assign)CGFloat centerPointRadiusOnStateIncorrect;
- @property (nonatomic, strong)UIColor *lineColorOnStateIncorrect;
- @property (nonatomic, strong)UIColor *fillColorOnStateIncorrect;
- @property (nonatomic, strong)UIColor *strokeColorOnStateIncorrect;
- @property (nonatomic, strong)UIColor *centerPointColorOnStateIncorrect;
- @end
- @implementation DBGuestureLock
- +(BOOL)passwordSetupStatus {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *password = [defaults valueForKey:DBGuestureLockPaswd];
- if (password == nil || [password length] <= 0) {
- return NO;
- }
-
- return YES;
- }
- +(void)clearGuestureLockPassword {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [defaults setValue: nil forKey:DBGuestureLockPaswd];
- }
- +(NSString *)getGuestureLockPassword {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *password = [defaults valueForKey:DBGuestureLockPaswd];
-
- return password;
- }
- -(BOOL)isPasswordSetup {
- return [[self class] passwordSetupStatus];
- }
- //@Override
- -(void)drawRect:(CGRect)rect {
- [super drawRect:rect];
-
- if ([self.selectedButtons count]== 0) {
- return;
- }
-
- UIBezierPath *path = [UIBezierPath bezierPath];
- [path setLineWidth: self.lineWidth];
- [self.lineColor set];
- [path setLineJoinStyle: kCGLineJoinRound];
- [path setLineCapStyle: kCGLineCapRound];
-
- for (NSInteger i=0; i<[self.selectedButtons count]; i++) {
- DBGuestureButton *button = self.selectedButtons[i];
- if (i == 0) {
- [path moveToPoint:[button center]];
- } else {
- [path addLineToPoint: [button center]];
- }
- [button setNeedsDisplay];
- }
- [path addLineToPoint:self.currentPoint];
- [path stroke];
- }
- +(instancetype)lockOnView:(UIView*)view delegate:(id<DBGuestureLockDelegate>)delegate {
- return [DBGuestureLock lockOnView:view offsetFromBottom:60.f delegate:delegate];
- }
- +(instancetype)lockOnView:(UIView*)view offsetFromBottom:(CGFloat)offset delegate:(id<DBGuestureLockDelegate>)delegate {
- CGFloat width = view.frame.size.height > view.frame.size.width ? view.frame.size.width : view.frame.size.height;
- CGFloat height = view.frame.size.height < view.frame.size.width ? view.frame.size.width : view.frame.size.height;
- CGRect frame = CGRectMake(0, height - width - offset, width, width);
- DBGuestureLock *lock = [[DBGuestureLock alloc] initWithFrame:frame];
-
- lock.delegate = delegate;
- lock.onPasswordSet = nil;
- lock.onGetCorrectPswd = nil;
- lock.onGetIncorrectPswd = nil;
-
- return lock;
- }
- +(instancetype)lockOnView:(UIView*)view onPasswordSet:(void (^)(DBGuestureLock *lock, NSString *password))onPasswordSet onGetCorrectPswd:(void (^)(DBGuestureLock *lock, NSString *password))onGetCorrectPswd onGetIncorrectPswd:(void (^)(DBGuestureLock *lock, NSString *password))onGetIncorrectPswd {
- return [DBGuestureLock lockOnView:view offsetFromBottom:60.f onPasswordSet:onPasswordSet onGetCorrectPswd:onGetCorrectPswd onGetIncorrectPswd:onGetIncorrectPswd];
- }
- +(instancetype)lockOnView:(UIView*)view offsetFromBottom:(CGFloat)offset onPasswordSet:(void (^)(DBGuestureLock *lock, NSString *password))onPasswordSet onGetCorrectPswd:(void (^)(DBGuestureLock *lock, NSString *password))onGetCorrectPswd onGetIncorrectPswd:(void (^)(DBGuestureLock *lock, NSString *password))onGetIncorrectPswd {
- CGFloat width = view.frame.size.height > view.frame.size.width ? view.frame.size.width : view.frame.size.height;
- CGFloat height = view.frame.size.height < view.frame.size.width ? view.frame.size.width : view.frame.size.height;
- CGRect frame = CGRectMake(0, height - width - offset, width, width);
- DBGuestureLock *lock = [[DBGuestureLock alloc] initWithFrame:frame];
-
- lock.delegate = nil;
- lock.onPasswordSet = onPasswordSet;
- lock.onGetCorrectPswd = onGetCorrectPswd;
- lock.onGetIncorrectPswd = onGetIncorrectPswd;
-
- return lock;
- }
- -(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{
- if (self.delegate) { //Work with block only
- return;
- }
-
- switch (buttonState) {
- case DBButtonStateNormal:
- self.lineColorOnStateNormal = lineColor;
- self.lineWidthOnStateNormal = lineWidth;
- self.strokeColorOnStateNormal = strokeColor;
- self.strokeWidthOnStateNormal = strokeWidth;
- self.circleRadiusOnStateNormal = circleRadius;
- self.fillColorOnStateNormal = fillColor;
- self.showCenterPointOnStateNormal = showCenterPoint;
- self.centerPointColorOnStateNormal = centerPointColor;
- self.centerPointRadiusOnStateNormal = centerPointRadius;
- self.fillCenterPointOnStateNormal = fillCenterPoint;
- break;
- case DBButtonStateSelected:
- self.lineColorOnStateSelected = lineColor;
- self.lineWidthOnStateSelected = lineWidth;
- self.strokeColorOnStateSelected = strokeColor;
- self.strokeWidthOnStateSelected = strokeWidth;
- self.circleRadiusOnStateSelected = circleRadius;
- self.fillColorOnStateSelected = fillColor;
- self.showCenterPointOnStateSelected = showCenterPoint;
- self.centerPointColorOnStateSelected = centerPointColor;
- self.centerPointRadiusOnStateSelected = centerPointRadius;
- self.fillCenterPointOnStateSelected = fillCenterPoint;
- break;
- case DBButtonStateIncorrect:
- self.lineColorOnStateIncorrect = lineColor;
- self.lineWidthOnStateIncorrect = lineWidth;
- self.strokeColorOnStateIncorrect = strokeColor;
- self.strokeWidthOnStateIncorrect = strokeWidth;
- self.circleRadiusOnStateIncorrect = circleRadius;
- self.fillColorOnStateIncorrect = fillColor;
- self.showCenterPointOnStateIncorrect = showCenterPoint;
- self.centerPointColorOnStateIncorrect = centerPointColor;
- self.centerPointRadiusOnStateIncorrect = centerPointRadius;
- self.fillCenterPointOnStateIncorrect = fillCenterPoint;
- break;
- default:
- break;
- }
-
- }
- //@Override
- -(instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame: frame];
- if (self) { // Draw 9 Lock Buttons
- [self setPropertiesByState:DBButtonStateNormal];
- _selectedButtons = [[NSMutableArray alloc] initWithCapacity:0];
- CGFloat width = frame.size.height > frame.size.width ? frame.size.width : frame.size.height;
- CGFloat spacing = width / 10; //Split into 10 Part
- CGFloat radius = spacing;
- [self setCircleRadius:radius];
- for (NSInteger i=0; i<9; i++) { //Total 9 buttons
- NSInteger row = i/3; //3 buttons for each row
- NSInteger col = i%3; //3 buttons for each column
-
- CGRect frame = CGRectMake((1+col*3)*spacing, (1+row*3)*spacing, 2*radius, 2*radius);
- DBGuestureButton *button = [[DBGuestureButton alloc] initWithFrame: frame];
- [button setTag: i+1]; // Present for password number
- [self addSubview: button];
- [self setBackgroundColor:[UIColor clearColor]];
- }
- }
-
- return self;
- }
- //@Override
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [super touchesBegan:touches withEvent:event];
-
- UITouch *touch = [touches anyObject];
- CGPoint point = [touch locationInView:self];
- self.currentPoint = point;
-
- for (DBGuestureButton *button in self.subviews) {
- if (CGRectContainsPoint(button.frame, point)) {
- [button setSelected:YES];
- if (![self.selectedButtons containsObject:button]) {
- [self.selectedButtons addObject:button];
- [self setPropertiesByState:DBButtonStateSelected];
- [button setNeedsDisplay];
- }
- }
- }
-
- [self setNeedsDisplay];
- }
- //@Override
- -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [super touchesMoved:touches withEvent:event];
-
- UITouch *touch = [touches anyObject];
- CGPoint point = [touch locationInView:self];
- self.currentPoint = point;
-
- for (DBGuestureButton *button in self.subviews) {
- if (CGRectContainsPoint(button.frame, point)) {
- [button setSelected:YES];
- if (![self.selectedButtons containsObject:button]) {
- [self.selectedButtons addObject:button];
- [self setPropertiesByState:DBButtonStateSelected];
- }
- }
- }
-
- [self setNeedsDisplay];
- }
- //@Override
- -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [super touchesEnded:touches withEvent:event];
-
- //Get password
- NSMutableString *password = [[NSMutableString alloc] initWithCapacity:0];
- for (NSInteger i=0; i<[self.selectedButtons count]; i++) {
- DBGuestureButton *button = self.selectedButtons[i];
- [password appendFormat:@"%li", (long)button.tag];
- }
-
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *correctPswd = [defaults valueForKey:DBGuestureLockPaswd];
- if (correctPswd == nil || [correctPswd length] <= 0) {
- [defaults setValue: password forKey:DBGuestureLockPaswd];
- if (self.delegate) {
- [self.delegate guestureLock:self didSetPassword:password];
- } else {
- self.onPasswordSet(self, password);
- }
- [self setPropertiesByState:DBButtonStateNormal];
- } else if ([password isEqualToString:correctPswd]) {
- if (self.delegate) {
- [self.delegate guestureLock:self didGetCorrectPswd:password];
- } else {
- self.onGetCorrectPswd(self, password);
- }
- [self setPropertiesByState:DBButtonStateNormal];
- } else { //incorrect
- if (self.delegate) {
- [self.delegate guestureLock:self didGetIncorrectPswd:password];
- } else {
- self.onGetIncorrectPswd(self, password);
- }
- [self setPropertiesByState:DBButtonStateIncorrect];
- }
-
- DBGuestureButton *lastButton = [self.selectedButtons lastObject];
- [self setCurrentPoint:lastButton.center];
- [self setNeedsDisplay];
- }
- -(void)resetButtons {
- for (NSInteger i=0; i<[self.selectedButtons count]; i++) {
- DBGuestureButton *button = self.selectedButtons[i];
- [button setSelected:NO];
- }
- [self.selectedButtons removeAllObjects];
- [self setNeedsDisplay];
- }
- -(void)lockState:(NSArray *)states {
- NSNumber *stateNumber = [states objectAtIndex:0];
- [self setPropertiesByState:[stateNumber integerValue]];
- }
- -(void)setPropertiesByState:(DBButtonState)buttonState {
- switch (buttonState) {
- case DBButtonStateNormal:
- [self setUserInteractionEnabled:YES];
- [self resetButtons];
-
- self.fillCenterPoint = YES; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(fillButtonCircleCenterPointOnState:)]) {
- self.fillCenterPoint = [self.delegate fillButtonCircleCenterPointOnState:DBButtonStateNormal];
- }
- } else if (self.fillCenterPointOnStateNormal) {
- self.fillCenterPoint = self.fillCenterPointOnStateNormal;
- }
-
- self.showCenterPoint = YES; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(showButtonCircleCenterPointOnState:)]) {
- self.showCenterPoint = [self.delegate showButtonCircleCenterPointOnState:DBButtonStateNormal];
- }
- } else if (self.showCenterPointOnStateNormal) {
- self.showCenterPoint = self.showCenterPointOnStateNormal;
- }
-
- self.strokeWidth = 1.f; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(widthOfButtonCircleStrokeOnState:)]) {
- self.strokeWidth = [self.delegate widthOfButtonCircleStrokeOnState:DBButtonStateNormal];
- }
- } else if (self.strokeWidthOnStateNormal) {
- self.strokeWidth = self.strokeWidthOnStateNormal;
- }
-
- self.centerPointRadius = 10.f; //As default
- if (self.delegate){
- if ([self.delegate respondsToSelector:@selector(radiusOfButtonCircleCenterPointOnState:)]) {
- self.centerPointRadius = [self.delegate radiusOfButtonCircleCenterPointOnState:DBButtonStateNormal];
- }
- } else if (self.centerPointColorOnStateNormal){
- self.centerPointColor = self.centerPointColorOnStateNormal;
- }
-
- self.lineWidth = 0.f;
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(lineWidthOfGuestureOnState:)]) {
- self.centerPointRadius = [self.delegate lineWidthOfGuestureOnState:DBButtonStateNormal];
- }
- } else if (self.lineWidthOnStateNormal) {
- self.lineWidth = self.lineWidthOnStateNormal;
- }
-
- self.lineColor = [UIColor whiteColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(lineColorOfGuestureOnState:)]) {
- self.lineColor = [self.delegate lineColorOfGuestureOnState:DBButtonStateNormal];
- }
- } else if (self.lineColorOnStateNormal) {
- self.lineColor = self.lineColorOnStateNormal;
- }
-
- //As default
- self.fillColor = [UIColor clearColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorForFillingButtonCircleOnState:)]) {
- self.fillColor = [self.delegate colorForFillingButtonCircleOnState:DBButtonStateNormal];
- }
- } else if (self.fillColorOnStateNormal) {
- self.fillColor = self.fillColorOnStateNormal;
- }
-
- //As default
- self.strokeColor = [UIColor clearColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorOfButtonCircleStrokeOnState:)]) {
- self.strokeColor = [self.delegate colorOfButtonCircleStrokeOnState:DBButtonStateNormal];
- }
- } else if (self.strokeColorOnStateNormal){
- self.strokeColor = self.strokeColorOnStateNormal;
- }
-
- //As default
- self.centerPointColor = [UIColor lightGrayColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorOfButtonCircleCenterPointOnState:)]) {
- self.centerPointColor = [self.delegate colorOfButtonCircleCenterPointOnState:DBButtonStateNormal];
- }
- } else if (self.centerPointColorOnStateNormal){
- self.centerPointColor = self.centerPointColorOnStateNormal;
- }
-
- //self.circleRadius = self.circleRadius;
- break;
- case DBButtonStateSelected:
- self.fillCenterPoint = YES; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(fillButtonCircleCenterPointOnState:)]) {
- self.fillCenterPoint = [self.delegate fillButtonCircleCenterPointOnState:DBButtonStateSelected];
- }
- } else if (self.fillCenterPointOnStateSelected) {
- self.fillCenterPoint = self.fillCenterPointOnStateSelected;
- }
-
- self.showCenterPoint = YES; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(showButtonCircleCenterPointOnState:)]) {
- self.showCenterPoint = [self.delegate showButtonCircleCenterPointOnState:DBButtonStateSelected];
- }
- } else if (self.showCenterPointOnStateSelected) {
- self.showCenterPoint = self.showCenterPointOnStateSelected;
- }
-
- self.strokeWidth = 1.f; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(widthOfButtonCircleStrokeOnState:)]) {
- self.strokeWidth = [self.delegate widthOfButtonCircleStrokeOnState:DBButtonStateSelected];
- }
- } else if (self.strokeWidthOnStateSelected) {
- self.strokeWidth = self.strokeWidthOnStateSelected;
- }
-
- self.centerPointRadius = 10.f; //As default
- if (self.delegate){
- if ([self.delegate respondsToSelector:@selector(radiusOfButtonCircleCenterPointOnState:)]) {
- self.centerPointRadius = [self.delegate radiusOfButtonCircleCenterPointOnState:DBButtonStateSelected];
- }
- } else if (self.centerPointColorOnStateSelected){
- self.centerPointColor = self.centerPointColorOnStateSelected;
- }
-
- self.lineWidth = 2.f;
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(lineWidthOfGuestureOnState:)]) {
- self.centerPointRadius = [self.delegate lineWidthOfGuestureOnState:DBButtonStateSelected];
- }
- } else if (self.lineWidthOnStateSelected) {
- self.lineWidth = self.lineWidthOnStateSelected;
- }
-
- self.lineColor = [UIColor whiteColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(lineColorOfGuestureOnState:)]) {
- self.lineColor = [self.delegate lineColorOfGuestureOnState:DBButtonStateSelected];
- }
- } else if (self.lineColorOnStateSelected) {
- self.lineColor = self.lineColorOnStateSelected;
- }
-
- //As default
- self.fillColor = [UIColor lightTextColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorForFillingButtonCircleOnState:)]) {
- self.fillColor = [self.delegate colorForFillingButtonCircleOnState:DBButtonStateSelected];
- }
- } else if (self.fillColorOnStateSelected) {
- self.fillColor = self.fillColorOnStateSelected;
- }
-
- //As default
- self.strokeColor = [UIColor whiteColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorOfButtonCircleStrokeOnState:)]) {
- self.strokeColor = [self.delegate colorOfButtonCircleStrokeOnState:DBButtonStateSelected];
- }
- } else if (self.strokeColorOnStateSelected){
- self.strokeColor = self.strokeColorOnStateSelected;
- }
-
- //As default
- self.centerPointColor = [UIColor whiteColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorOfButtonCircleCenterPointOnState:)]) {
- self.centerPointColor = [self.delegate colorOfButtonCircleCenterPointOnState:DBButtonStateSelected];
- }
- } else if (self.centerPointColorOnStateSelected){
- self.centerPointColor = self.centerPointColorOnStateSelected;
- }
-
- //self.circleRadius = self.circleRadius;
- break;
- case DBButtonStateIncorrect:
- [self setUserInteractionEnabled:NO];
-
- self.fillCenterPoint = YES; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(fillButtonCircleCenterPointOnState:)]) {
- self.fillCenterPoint = [self.delegate fillButtonCircleCenterPointOnState:DBButtonStateIncorrect];
- }
- } else if (self.fillCenterPointOnStateIncorrect) {
- self.fillCenterPoint = self.fillCenterPointOnStateIncorrect;
- }
-
- self.showCenterPoint = YES; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(showButtonCircleCenterPointOnState:)]) {
- self.showCenterPoint = [self.delegate showButtonCircleCenterPointOnState:DBButtonStateIncorrect];
- }
- } else if (self.showCenterPointOnStateIncorrect) {
- self.showCenterPoint = self.showCenterPointOnStateIncorrect;
- }
-
- self.strokeWidth = 1.f; //As default
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(widthOfButtonCircleStrokeOnState:)]) {
- self.strokeWidth = [self.delegate widthOfButtonCircleStrokeOnState:DBButtonStateIncorrect];
- }
- } else if (self.strokeWidthOnStateIncorrect) {
- self.strokeWidth = self.strokeWidthOnStateIncorrect;
- }
-
- self.centerPointRadius = 10.f; //As default
- if (self.delegate){
- if ([self.delegate respondsToSelector:@selector(radiusOfButtonCircleCenterPointOnState:)]) {
- self.centerPointRadius = [self.delegate radiusOfButtonCircleCenterPointOnState:DBButtonStateIncorrect];
- }
- } else if (self.centerPointColorOnStateIncorrect){
- self.centerPointColor = self.centerPointColorOnStateIncorrect;
- }
-
- self.lineWidth = 5.f;
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(lineWidthOfGuestureOnState:)]) {
- self.centerPointRadius = [self.delegate lineWidthOfGuestureOnState:DBButtonStateIncorrect];
- }
- } else if (self.lineWidthOnStateIncorrect) {
- self.lineWidth = self.lineWidthOnStateIncorrect;
- }
-
- self.lineColor = [UIColor orangeColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(lineColorOfGuestureOnState:)]) {
- self.lineColor = [self.delegate lineColorOfGuestureOnState:DBButtonStateIncorrect];
- }
- } else if (self.lineColorOnStateIncorrect) {
- self.lineColor = self.lineColorOnStateIncorrect;
- }
-
- //As default
- self.fillColor = [UIColor lightTextColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorForFillingButtonCircleOnState:)]) {
- self.fillColor = [self.delegate colorForFillingButtonCircleOnState:DBButtonStateIncorrect];
- }
- } else if (self.fillColorOnStateIncorrect) {
- self.fillColor = self.fillColorOnStateIncorrect;
- }
-
- //As default
- self.strokeColor = [UIColor orangeColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorOfButtonCircleStrokeOnState:)]) {
- self.strokeColor = [self.delegate colorOfButtonCircleStrokeOnState:DBButtonStateIncorrect];
- }
- } else if (self.strokeColorOnStateIncorrect){
- self.strokeColor = self.strokeColorOnStateIncorrect;
- }
-
- //As default
- self.centerPointColor = [UIColor orangeColor];
- if (self.delegate) {
- if ([self.delegate respondsToSelector:@selector(colorOfButtonCircleCenterPointOnState:)]) {
- self.centerPointColor = [self.delegate colorOfButtonCircleCenterPointOnState:DBButtonStateIncorrect];
- }
- } else if (self.centerPointColorOnStateIncorrect){
- self.centerPointColor = self.centerPointColorOnStateIncorrect;
- }
-
- //self.circleRadius = self.circleRadius;
- [self performSelector:@selector(lockState:) withObject:[NSArray arrayWithObject:[NSNumber numberWithInteger:DBButtonStateNormal]] afterDelay:1.f];
- break;
- default:
- break;
- }
- }
- @end
|