Skip to content

Commit 2c81fc3

Browse files
committed
Added horizontal layout to keypad view
1 parent 7d0bd19 commit 2c81fc3

File tree

11 files changed

+229
-66
lines changed

11 files changed

+229
-66
lines changed

TOPasscodeViewController/Models/TOPasscodeViewContentLayout.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ + (TOPasscodeViewContentLayout *)defaultScreenContentLayout
4747

4848
/* Circle Button Label */
4949
contentLayout.circleButtonTitleLabelFont = [UIFont systemFontOfSize:37.5f weight:UIFontWeightThin];
50-
contentLayout.circleButtonLetteringLabelFont = [UIFont monospacedDigitSystemFontOfSize:9.0f weight:UIFontWeightThin];
50+
contentLayout.circleButtonLetteringLabelFont = [UIFont systemFontOfSize:9.0f weight:UIFontWeightThin];
5151
contentLayout.circleButtonLabelSpacing = 6.0f;
5252
contentLayout.circleButtonLetteringSpacing = 3.0f;
5353

@@ -89,7 +89,7 @@ + (TOPasscodeViewContentLayout *)mediumScreenContentLayout
8989

9090
/* Circle Button Label */
9191
contentLayout.circleButtonTitleLabelFont = [UIFont systemFontOfSize:36.5f weight:UIFontWeightThin];
92-
contentLayout.circleButtonLetteringLabelFont = [UIFont monospacedDigitSystemFontOfSize:8.5f weight:UIFontWeightThin];
92+
contentLayout.circleButtonLetteringLabelFont = [UIFont systemFontOfSize:8.5f weight:UIFontWeightThin];
9393
contentLayout.circleButtonLabelSpacing = 5.0f;
9494
contentLayout.circleButtonLetteringSpacing = 2.5f;
9595

@@ -135,7 +135,7 @@ + (TOPasscodeViewContentLayout *)smallScreenContentLayout
135135

136136
/* Circle Button Label */
137137
contentLayout.circleButtonTitleLabelFont = [UIFont systemFontOfSize:32.0f weight:UIFontWeightThin];
138-
contentLayout.circleButtonLetteringLabelFont = [UIFont monospacedDigitSystemFontOfSize:7.0f weight:UIFontWeightThin];
138+
contentLayout.circleButtonLetteringLabelFont = [UIFont systemFontOfSize:7.0f weight:UIFontWeightThin];
139139
contentLayout.circleButtonLabelSpacing = 4.5f;
140140
contentLayout.circleButtonLetteringSpacing = 2.0f;
141141

TOPasscodeViewController/TOPasscodeSettingsViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ - (void)viewDidLoad {
140140

141141
// Add callbacks for the keypad view
142142
self.keypadView.numberButtonTappedHandler = ^(NSInteger number) {
143-
NSString *numberString = [NSString stringWithFormat:@"%ld", number];
143+
NSString *numberString = [NSString stringWithFormat:@"%ld", (long)number];
144144
[weakSelf.inputField appendPasscodeCharacters:numberString animated:NO];
145145
};
146146

TOPasscodeViewController/Views/Main/TOPasscodeCircleButton.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ NS_ASSUME_NONNULL_BEGIN
1515

1616
@interface TOPasscodeCircleButton : UIControl
1717

18+
// Alpha value that properly controls the necessary subviews
19+
@property (nonatomic, assign) CGFloat contentAlpha;
20+
1821
// Required to be set before this view can be properly rendered
1922
@property (nonatomic, strong) UIImage *backgroundImage;
2023
@property (nonatomic, strong) UIImage *hightlightedBackgroundImage;

TOPasscodeViewController/Views/Main/TOPasscodeCircleButton.m

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ - (instancetype)initWithNumberString:(NSString *)numberString letteringString:(N
2828
if (self = [super init]) {
2929
_numberString = numberString;
3030
_letteringString = letteringString;
31+
_contentAlpha = 1.0f;
3132
[self setUp];
3233
}
3334

@@ -159,21 +160,21 @@ - (UIImage *)hightlightedBackgroundImage { return self.circleView.highlightedCir
159160

160161
- (void)setNumberFont:(UIFont *)numberFont
161162
{
162-
self.buttonLabel.numberLabel.font = numberFont;
163+
self.buttonLabel.numberLabelFont = numberFont;
163164
[self setNeedsLayout];
164165
}
165166

166-
- (UIFont *)numberFont { return self.buttonLabel.numberLabel.font; }
167+
- (UIFont *)numberFont { return self.buttonLabel.numberLabelFont; }
167168

168169
/***********************************************************/
169170

170171
- (void)setLetteringFont:(UIFont *)letteringFont
171172
{
172-
self.buttonLabel.letteringLabel.font = letteringFont;
173+
self.buttonLabel.letteringLabelFont = letteringFont;
173174
[self setNeedsLayout];
174175
}
175176

176-
- (UIFont *)letteringFont { return self.buttonLabel.letteringLabel.font; }
177+
- (UIFont *)letteringFont { return self.buttonLabel.letteringLabelFont; }
177178

178179
/***********************************************************/
179180

@@ -204,4 +205,18 @@ - (void)setTextColor:(UIColor *)textColor
204205
self.buttonLabel.textColor = _textColor;
205206
}
206207

208+
/***********************************************************/
209+
210+
- (void)setContentAlpha:(CGFloat)contentAlpha
211+
{
212+
if (_contentAlpha == contentAlpha) {
213+
return;
214+
}
215+
216+
_contentAlpha = contentAlpha;
217+
218+
self.buttonLabel.alpha = contentAlpha;
219+
self.circleView.alpha = contentAlpha;
220+
}
221+
207222
@end

TOPasscodeViewController/Views/Main/TOPasscodeKeypadView.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ NS_ASSUME_NONNULL_BEGIN
1212

1313
@class TOPasscodeCircleButton;
1414

15+
/* The direction this keypad is laid out.
16+
When horizontal, the '0' button is on the right side */
17+
typedef NS_ENUM(NSInteger, TOPasscodeKeypadLayout) {
18+
TOPasscodeKeypadLayoutVertical,
19+
TOPasscodeKeypadLayoutHorizontal
20+
};
21+
1522
@interface TOPasscodeKeypadView : UIView
1623

24+
/** The type of layout for the buttons (Default is vertical) */
25+
@property (nonatomic, assign) TOPasscodeKeypadLayout layout;
26+
1727
/** The vibrancy effect to be applied to each button background */
1828
@property (nonatomic, strong, nullable) UIVibrancyEffect *vibrancyEffect;
1929

@@ -61,11 +71,14 @@ NS_ASSUME_NONNULL_BEGIN
6171
@property (nonatomic, strong, nullable) UIView *rightAccessoryView;
6272

6373
/** The controls making up each of the button views */
64-
@property (nonatomic, readonly) NSArray<TOPasscodeCircleButton *> *pinButtons;
74+
@property (nonatomic, readonly) NSArray<TOPasscodeCircleButton *> *keypadButtons;
6575

6676
/** The block that is triggered whenever a user taps one of the buttons */
6777
@property (nonatomic, copy) void (^buttonTappedHandler)(NSInteger buttonNumber);
6878

79+
/* Perform an animation of a set duration to the new layout */
80+
- (void)setLayout:(TOPasscodeKeypadLayout)layout animated:(BOOL)animated duration:(CGFloat)duration;
81+
6982
@end
7083

7184
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)