From ab916158a3320f4fa2a86930d214ec479ba58385 Mon Sep 17 00:00:00 2001 From: Giacomo Tufano Date: Fri, 27 Feb 2015 10:00:34 +0100 Subject: [PATCH] Add a squareButtons property to THPinViewController to make buttons square. Tentatively fixes #19 --- THPinViewController/THPinNumButton.h | 2 +- THPinViewController/THPinNumButton.m | 6 ++++-- THPinViewController/THPinNumPadView.h | 1 + THPinViewController/THPinNumPadView.m | 12 +++++++++++- THPinViewController/THPinView.h | 1 + THPinViewController/THPinView.m | 10 ++++++++++ THPinViewController/THPinViewController.h | 1 + THPinViewController/THPinViewController.m | 1 + 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/THPinViewController/THPinNumButton.h b/THPinViewController/THPinNumButton.h index 7ce67b8..7c3bc21 100644 --- a/THPinViewController/THPinNumButton.h +++ b/THPinViewController/THPinNumButton.h @@ -14,7 +14,7 @@ @property (nonatomic, readonly, assign) NSUInteger number; @property (nonatomic, readonly, copy) NSString *letters; -- (instancetype)initWithNumber:(NSUInteger)number letters:(NSString *)letters NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithNumber:(NSUInteger)number letters:(NSString *)letters squareButton:(BOOL)squareButton NS_DESIGNATED_INITIALIZER; + (CGFloat)diameter; diff --git a/THPinViewController/THPinNumButton.m b/THPinViewController/THPinNumButton.m index bfebbc3..eea5c6a 100644 --- a/THPinViewController/THPinNumButton.m +++ b/THPinViewController/THPinNumButton.m @@ -23,7 +23,7 @@ @interface THPinNumButton () @implementation THPinNumButton -- (instancetype)initWithNumber:(NSUInteger)number letters:(NSString *)letters +- (instancetype)initWithNumber:(NSUInteger)number letters:(NSString *)letters squareButton:(BOOL)squareButton { self = [super init]; if (self) @@ -31,7 +31,9 @@ - (instancetype)initWithNumber:(NSUInteger)number letters:(NSString *)letters _number = number; _letters = letters; - self.layer.cornerRadius = [[self class] diameter] / 2.0f; + if (!squareButton) { + self.layer.cornerRadius = [[self class] diameter] / 2.0f; + } self.layer.borderWidth = 1.0f; UIView *contentView = [[UIView alloc] init]; diff --git a/THPinViewController/THPinNumPadView.h b/THPinViewController/THPinNumPadView.h index 4c5d2f4..befb95e 100644 --- a/THPinViewController/THPinNumPadView.h +++ b/THPinViewController/THPinNumPadView.h @@ -21,6 +21,7 @@ @property (nonatomic, weak) id delegate; @property (nonatomic, assign) BOOL hideLetters; +@property (nonatomic, assign) BOOL squareButtons; - (instancetype)initWithDelegate:(id)delegate; diff --git a/THPinViewController/THPinNumPadView.m b/THPinViewController/THPinNumPadView.m index de47e5b..5c32bc8 100644 --- a/THPinViewController/THPinNumPadView.m +++ b/THPinViewController/THPinNumPadView.m @@ -78,7 +78,8 @@ - (void)setupViews NSUInteger number = (row < 3) ? row * 3 + col + 1 : 0; THPinNumButton *button = [[THPinNumButton alloc] initWithNumber:number - letters:[self lettersForRow:row column:col]]; + letters:[self lettersForRow:row column:col] + squareButton:self.squareButtons]; button.translatesAutoresizingMaskIntoConstraints = NO; button.backgroundColor = self.backgroundColor; [button addTarget:self action:@selector(numberButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; @@ -183,6 +184,15 @@ - (void)setHideLetters:(BOOL)hideLetters [self setupViews]; } +- (void)setSquareButtons:(BOOL)squareButtons +{ + if (self.squareButtons == squareButtons) { + return; + } + _squareButtons = squareButtons; + [self setupViews]; +} + - (void)numberButtonTapped:(id)sender { [self.delegate pinNumPadView:self numberTapped:[(THPinNumButton *)sender number]]; diff --git a/THPinViewController/THPinView.h b/THPinViewController/THPinView.h index 0adaf07..12f5b6e 100644 --- a/THPinViewController/THPinView.h +++ b/THPinViewController/THPinView.h @@ -29,6 +29,7 @@ @property (nonatomic, strong) UIColor *promptColor; @property (nonatomic, assign) BOOL hideLetters; @property (nonatomic, assign) BOOL disableCancel; +@property (nonatomic, assign) BOOL squareButtons; - (instancetype)initWithDelegate:(id)delegate NS_DESIGNATED_INITIALIZER; diff --git a/THPinViewController/THPinView.m b/THPinViewController/THPinView.m index cd813a7..b56c075 100644 --- a/THPinViewController/THPinView.m +++ b/THPinViewController/THPinView.m @@ -176,6 +176,16 @@ - (void)setHideLetters:(BOOL)hideLetters self.numPadView.hideLetters = hideLetters; } +- (BOOL)squareButtons +{ + return self.numPadView.squareButtons; +} + +- (void)setSquareButtons:(BOOL)squareButtons +{ + self.numPadView.squareButtons = squareButtons; +} + - (void)setDisableCancel:(BOOL)disableCancel { if (self.disableCancel == disableCancel) { diff --git a/THPinViewController/THPinViewController.h b/THPinViewController/THPinViewController.h index 3402b8a..a308e7c 100644 --- a/THPinViewController/THPinViewController.h +++ b/THPinViewController/THPinViewController.h @@ -41,6 +41,7 @@ static const NSInteger THPinViewControllerContentViewTag = 14742; @property (nonatomic, strong) UIColor *promptColor; @property (nonatomic, assign) BOOL hideLetters; // hides the letters on the number buttons @property (nonatomic, assign) BOOL disableCancel; // hides the cancel button +@property (nonatomic, assign) BOOL squareButtons; // makes the buttons squares, not cirles - (instancetype)initWithDelegate:(id)delegate NS_DESIGNATED_INITIALIZER; diff --git a/THPinViewController/THPinViewController.m b/THPinViewController/THPinViewController.m index 6005568..0ecfd49 100644 --- a/THPinViewController/THPinViewController.m +++ b/THPinViewController/THPinViewController.m @@ -50,6 +50,7 @@ - (void)viewDidLoad self.pinView.promptTitle = self.promptTitle; self.pinView.promptColor = self.promptColor; self.pinView.hideLetters = self.hideLetters; + self.pinView.squareButtons = self.squareButtons; self.pinView.disableCancel = self.disableCancel; self.pinView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:self.pinView];