Skip to content

Commit

Permalink
Add a squareButtons property to THPinViewController to make buttons s…
Browse files Browse the repository at this point in the history
…quare. Tentatively fixes antiraum#19
  • Loading branch information
ilTofa committed Feb 27, 2015
1 parent 1574020 commit ab91615
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion THPinViewController/THPinNumButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions THPinViewController/THPinNumButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ @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)
{
_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];
Expand Down
1 change: 1 addition & 0 deletions THPinViewController/THPinNumPadView.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@property (nonatomic, weak) id<THPinNumPadViewDelegate> delegate;
@property (nonatomic, assign) BOOL hideLetters;
@property (nonatomic, assign) BOOL squareButtons;

- (instancetype)initWithDelegate:(id<THPinNumPadViewDelegate>)delegate;

Expand Down
12 changes: 11 additions & 1 deletion THPinViewController/THPinNumPadView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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]];
Expand Down
1 change: 1 addition & 0 deletions THPinViewController/THPinView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<THPinViewDelegate>)delegate NS_DESIGNATED_INITIALIZER;

Expand Down
10 changes: 10 additions & 0 deletions THPinViewController/THPinView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions THPinViewController/THPinViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<THPinViewControllerDelegate>)delegate NS_DESIGNATED_INITIALIZER;

Expand Down
1 change: 1 addition & 0 deletions THPinViewController/THPinViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit ab91615

Please sign in to comment.