Skip to content

Commit 84cf1f8

Browse files
committed
Added dark mode to keypadv view
1 parent 0cde450 commit 84cf1f8

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed

TOPasscodeViewController/TOPasscodeSettingsViewController.m

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import "TOPasscodeSettingsKeypadView.h"
1212
#import "TOPasscodeSettingsWarningLabel.h"
1313

14-
const CGFloat kTOPasscodeSettingsLabelInputSpacing = 15.0f;
14+
const CGFloat kTOPasscodeSettingsLabelInputSpacing = 18.0f;
1515
const CGFloat kTOPasscodeKeypadMaxSizeRatio = 0.40f;
1616
const CGFloat kTOPasscodeKeypadMinHeight = 200.0f;
1717
const CGFloat kTOPasscodeKeypadMaxHeight = 330.0f;
@@ -74,6 +74,8 @@ - (void)viewDidLoad {
7474

7575
// Create label view
7676
self.warningLabel = [[TOPasscodeSettingsWarningLabel alloc] initWithFrame:CGRectZero];
77+
self.warningLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
78+
self.warningLabel.hidden = YES;
7779
[self.containerView addSubview:self.warningLabel];
7880

7981
// Add callbacks for the keypad view
@@ -88,7 +90,7 @@ - (void)viewDidLoad {
8890
CGRect frame = self.containerView.frame;
8991
frame.size.width = self.view.bounds.size.width;
9092
frame.size.height = CGRectGetHeight(self.titleLabel.frame) + CGRectGetHeight(self.numberInputView.frame)
91-
+ kTOPasscodeSettingsLabelInputSpacing;
93+
+ (kTOPasscodeSettingsLabelInputSpacing * 2.0f);
9294
self.containerView.frame = CGRectIntegral(frame);
9395

9496
// Set frame of title label
@@ -102,8 +104,14 @@ - (void)viewDidLoad {
102104
frame.origin.y = (CGRectGetHeight(self.titleLabel.frame) + kTOPasscodeSettingsLabelInputSpacing);
103105
self.numberInputView.frame = CGRectIntegral(frame);
104106

107+
// Set the frame for the warning view
108+
frame = self.warningLabel.frame;
109+
frame.origin.x = (CGRectGetWidth(self.view.frame) - CGRectGetWidth(frame)) * 0.5f;
110+
frame.origin.y = CGRectGetMaxY(self.numberInputView.frame) + kTOPasscodeSettingsLabelInputSpacing;
111+
self.warningLabel.frame = frame;
112+
105113
// Apply light/dark mode
106-
[self applyThemeForStyle:self.style];
114+
[self applyThemeForStyle:TOPasscodeSettingsViewStyleDark];
107115
}
108116

109117
- (void)viewDidLayoutSubviews
@@ -138,15 +146,36 @@ - (void)applyThemeForStyle:(TOPasscodeSettingsViewStyle)style
138146
{
139147
BOOL isDark = (style == TOPasscodeSettingsViewStyleDark);
140148

149+
// Set background color
141150
UIColor *backgroundColor;
142151
if (isDark) {
143-
backgroundColor = [UIColor colorWithWhite:0.2f alpha:1.0f];
152+
backgroundColor = [UIColor colorWithWhite:0.15f alpha:1.0f];
144153
}
145154
else {
146155
backgroundColor = [UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:241.0f/255.0f alpha:1.0f];
147156
}
148157
self.view.backgroundColor = backgroundColor;
149158

159+
// Set the style of the keypad view
160+
self.keypadView.style = style;
161+
162+
// Set the color for the input content
163+
UIColor *inputColor = isDark ? [UIColor whiteColor] : [UIColor blackColor];
164+
165+
// Set the label style
166+
self.titleLabel.textColor = inputColor;
167+
168+
// Set the number input tint
169+
self.numberInputView.tintColor = inputColor;
170+
171+
// Set the tint color of the incorrect warning label
172+
UIColor *warningColor = nil;
173+
if (isDark) {
174+
warningColor = [UIColor colorWithRed:214.0f/255.0f green:63.0f/255.0f blue:63.0f/255.0f alpha:1.0f];
175+
}
176+
else {
177+
warningColor = [UIColor colorWithRed:214.0f/255.0f green:63.0f/255.0f blue:63.0f/255.0f alpha:1.0f];
178+
}
150179
}
151180

152181
@end

TOPasscodeViewController/Views/TOPasscodeSettingsKeypadButton.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ - (void)setBottomInset:(CGFloat)bottomInset
5151
[self setNeedsLayout];
5252
}
5353

54+
#pragma mark - Control Accessor -
55+
- (void)setEnabled:(BOOL)enabled
56+
{
57+
[super setEnabled:enabled];
58+
self.buttonLabel.alpha = enabled ? 1.0f : 0.5f;
59+
}
60+
5461
#pragma mark - Background Image Accessor -
5562

5663
- (void)setHighlighted:(BOOL)highlighted {

TOPasscodeViewController/Views/TOPasscodeSettingsKeypadView.h

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

1414
@interface TOPasscodeSettingsKeypadView : UIView
1515

16+
/* Whether the control is allowing input */
17+
@property (nonatomic, assign) BOOL enabled;
18+
1619
/* Whether the view is currently light mode or dark. */
1720
@property (nonatomic, assign) TOPasscodeSettingsViewStyle style;
1821

TOPasscodeViewController/Views/TOPasscodeSettingsKeypadView.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ - (void)setUpDefaultValuesForStye:(TOPasscodeSettingsViewStyle)style
108108
// Keypad label
109109
self.keypadButtonLabelTextColor = isDark ? [UIColor whiteColor] : [UIColor blackColor];
110110

111-
self.keypadButtonForegroundColor = isDark ? [UIColor colorWithWhite:0.3f alpha:1.0f] : [UIColor whiteColor];
112-
self.keypadButtonTappedForegroundColor = isDark ? [UIColor colorWithWhite:0.4f alpha:1.0f] : [UIColor colorWithWhite:0.85f alpha:1.0f];
111+
self.keypadButtonForegroundColor = isDark ? [UIColor colorWithWhite:0.35f alpha:1.0f] : [UIColor whiteColor];
112+
self.keypadButtonTappedForegroundColor = isDark ? [UIColor colorWithWhite:0.45f alpha:1.0f] : [UIColor colorWithWhite:0.85f alpha:1.0f];
113113

114114
// Button border color
115115
UIColor *borderColor = nil;
116116
if (isDark) {
117-
borderColor = [UIColor colorWithWhite:0.2 alpha:1.0f];
117+
borderColor = [UIColor colorWithWhite:0.15f alpha:1.0f];
118118
}
119119
else {
120120
borderColor = [UIColor colorWithRed:166.0f/255.0f green:174.0f/255.0f blue:186.0f/255.0f alpha:1.0f];
@@ -124,7 +124,7 @@ - (void)setUpDefaultValuesForStye:(TOPasscodeSettingsViewStyle)style
124124
// Background Color
125125
UIColor *backgroundColor = nil;
126126
if (isDark) {
127-
backgroundColor = [UIColor colorWithWhite:0.3f alpha:1.0f];
127+
backgroundColor = [UIColor colorWithWhite:0.18f alpha:1.0f];
128128
}
129129
else {
130130
backgroundColor = [UIColor colorWithRed:220.0f/255.0f green:225.0f/255.0f blue:232.0f/255.0f alpha:1.0f];
@@ -140,6 +140,8 @@ - (void)setUpDefaultValuesForStye:(TOPasscodeSettingsViewStyle)style
140140
separatorColor = [UIColor colorWithWhite:0.7f alpha:1.0f];
141141
}
142142
self.separatorView.backgroundColor = separatorColor;
143+
144+
self.deleteButton.tintColor = isDark ? [UIColor whiteColor] : [UIColor blackColor];
143145
}
144146

145147
- (void)setUpImagesIfNeeded
@@ -353,4 +355,15 @@ - (void)setKeypadButtonTappedForegroundColor:(nullable UIColor *)keypadButtonTap
353355
[self setNeedsLayout];
354356
}
355357

358+
- (void)setEnabled:(BOOL)enabled
359+
{
360+
_enabled = enabled;
361+
362+
for (TOPasscodeSettingsKeypadButton *button in self.keypadButtons) {
363+
button.enabled = enabled;
364+
}
365+
366+
self.deleteButton.enabled = enabled;
367+
}
368+
356369
@end

TOPasscodeViewController/Views/TOPasscodeSettingsWarningLabel.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ - (instancetype)initWithFrame:(CGRect)frame
2929

3030
- (void)setUp
3131
{
32-
_textPadding = CGSizeMake(12.0f, 4.0f);
32+
_numberOfWarnings = 0;
33+
_textPadding = CGSizeMake(14.0f, 6.0f);
3334

3435
self.tintColor = [UIColor colorWithRed:214.0f/255.0f green:63.0f/255.0f blue:63.0f/255.0f alpha:1.0f];
3536

3637
self.label = [[UILabel alloc] initWithFrame:CGRectZero];
38+
self.label.backgroundColor = [UIColor clearColor];
3739
self.label.textAlignment = NSTextAlignmentCenter;
3840
self.label.textColor = [UIColor whiteColor];
3941
self.label.font = [UIFont systemFontOfSize:15.0f];
@@ -53,6 +55,8 @@ - (void)didMoveToSuperview
5355
- (void)sizeToFit
5456
{
5557
[super sizeToFit];
58+
[self.label sizeToFit];
59+
5660
CGRect frame = self.frame;
5761
CGRect labelFrame = self.label.frame;
5862

@@ -69,7 +73,7 @@ - (void)layoutSubviews
6973
CGRect labelFrame = self.label.frame;
7074

7175
labelFrame.origin.x = (CGRectGetWidth(frame) - CGRectGetWidth(labelFrame)) * 0.5f;
72-
labelFrame.origin.y = (CGRectGetWidth(frame) - CGRectGetWidth(labelFrame)) * 0.5f;
76+
labelFrame.origin.y = (CGRectGetHeight(frame) - CGRectGetHeight(labelFrame)) * 0.5f;
7377
self.label.frame = labelFrame;
7478
}
7579

@@ -82,7 +86,7 @@ - (void)setTextForCount:(NSInteger)count
8286
text = NSLocalizedString(@"1 Failed Passcode Attempt", @"");
8387
}
8488
else {
85-
text = [NSString stringWithFormat:NSLocalizedString(@"%@ Failed Passcode Attempts", @""), count];
89+
text = [NSString stringWithFormat:NSLocalizedString(@"%d Failed Passcode Attempts", @""), count];
8690
}
8791
self.label.text = text;
8892

@@ -122,8 +126,8 @@ + (UIImage *)roundedBackgroundImageWithHeight:(CGFloat)height
122126

123127
CGFloat halfHeight = height * 0.5f;
124128
UIEdgeInsets insets = UIEdgeInsetsMake(halfHeight, halfHeight, halfHeight, halfHeight);
125-
image = [image resizableImageWithCapInsets:insets];
126129
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
130+
image = [image resizableImageWithCapInsets:insets];
127131
return image;
128132
}
129133

0 commit comments

Comments
 (0)