Skip to content

Commit 0a02eca

Browse files
committed
Added provions for multiline titles
1 parent 9cc3624 commit 0a02eca

File tree

2 files changed

+105
-13
lines changed

2 files changed

+105
-13
lines changed

TOPasscodeViewController/Views/Main/TOPasscodeView.m

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ - (void)setUp
7979
#pragma mark - View Layout -
8080
- (void)layoutSubviews
8181
{
82+
CGSize viewSize = self.frame.size;
8283
CGSize midViewSize = (CGSize){self.frame.size.width * 0.5f, self.frame.size.height * 0.5f};
8384

8485
CGRect frame = CGRectZero;
@@ -112,10 +113,28 @@ - (void)layoutSubviews
112113
y = CGRectGetMaxY(frame) + self.currentLayout.circleRowBottomSpacing;
113114

114115
// PIN Pad View
115-
frame = self.keypadView.frame;
116-
frame.origin.y = y;
117-
frame.origin.x = midViewSize.width - (CGRectGetWidth(frame) * 0.5f);
118-
self.keypadView.frame = CGRectIntegral(frame);
116+
if (self.keypadView) {
117+
frame = self.keypadView.frame;
118+
frame.origin.y = y;
119+
frame.origin.x = midViewSize.width - (CGRectGetWidth(frame) * 0.5f);
120+
self.keypadView.frame = CGRectIntegral(frame);
121+
}
122+
123+
// If the keypad view is hidden, lay out the left button manually
124+
if (!self.keypadView && self.leftButton) {
125+
frame = self.leftButton.frame;
126+
frame.origin.x = 0.0f;
127+
frame.origin.y = y;
128+
self.leftButton.frame = frame;
129+
}
130+
131+
// If the keypad view is hidden, lay out the right button manually
132+
if (!self.keypadView && self.rightButton) {
133+
frame = self.rightButton.frame;
134+
frame.origin.x = viewSize.width - frame.size.width;
135+
frame.origin.y = y;
136+
self.rightButton.frame = frame;
137+
}
119138
}
120139

121140
- (void)sizeToFitWidth:(CGFloat)width
@@ -142,30 +161,52 @@ - (void)sizeToFitWidth:(CGFloat)width
142161

143162
- (void)sizeToFit
144163
{
145-
[self.titleLabel sizeToFit];
146-
[self.inputField sizeToFit];
147-
[self.keypadView sizeToFit];
148-
149164
CGRect frame = self.frame;
150-
frame.size.width = CGRectGetWidth(self.keypadView.frame);
165+
frame.size.width = 0.0f;
151166
frame.size.height = 0.0f;
152167

168+
[self.keypadView sizeToFit];
169+
[self.inputField sizeToFit];
170+
171+
if (self.keypadView) {
172+
frame.size.width = self.keypadView.frame.size.width;
173+
}
174+
else {
175+
frame.size.width = self.inputField.frame.size.width;
176+
}
177+
153178
// Add height for the title view
154179
if (self.titleView) {
155180
frame.size.height += self.titleView.frame.size.height;
156181
frame.size.height += self.currentLayout.titleViewBottomSpacing;
157182
}
158183

159184
// Add height for the title label
160-
frame.size.height += self.titleLabel.frame.size.height;
185+
CGRect titleFrame = self.titleLabel.frame;
186+
titleFrame.size = [self.titleLabel sizeThatFits:(CGSize){frame.size.width, CGFLOAT_MAX}];
187+
self.titleLabel.frame = titleFrame;
188+
189+
frame.size.height += titleFrame.size.height;
161190
frame.size.height += self.currentLayout.titleLabelBottomSpacing;
162191

163192
// Add height for the circle rows
164193
frame.size.height += self.inputField.frame.size.height;
165194
frame.size.height += self.currentLayout.circleRowBottomSpacing;
166195

167196
// Add height for the keypad
168-
frame.size.height += self.keypadView.frame.size.height;
197+
if (self.keypadView) {
198+
frame.size.height += self.keypadView.frame.size.height;
199+
}
200+
else { // If no keypad, just factor in the accessory buttons
201+
[self.leftButton sizeToFit];
202+
[self.rightButton sizeToFit];
203+
204+
CGFloat maxHeight = 0.0f;
205+
maxHeight = MAX(self.leftButton.frame.size.height, 0.0f);
206+
maxHeight = MAX(self.rightButton.frame.size.height, maxHeight);
207+
208+
frame.size.height += maxHeight;
209+
}
169210

170211
// Set the frame back
171212
self.frame = CGRectIntegral(frame);
@@ -184,6 +225,7 @@ - (void)setUpViewForType:(TOPasscodeType)type
184225
}
185226
self.titleLabel.text = self.titleText;
186227
self.titleLabel.textAlignment = NSTextAlignmentCenter;
228+
self.titleLabel.numberOfLines = 0;
187229
[self.titleLabel sizeToFit];
188230
[self addSubview:self.titleLabel];
189231

@@ -384,14 +426,26 @@ - (void)setLeftButton:(UIButton *)leftButton
384426
{
385427
if (leftButton == _leftButton) { return; }
386428
_leftButton = leftButton;
387-
self.keypadView.leftAccessoryView = leftButton;
429+
430+
if (self.keypadView) {
431+
self.keypadView.leftAccessoryView = leftButton;
432+
}
433+
else {
434+
[self addSubview:_leftButton];
435+
}
388436
}
389437

390438
- (void)setRightButton:(UIButton *)rightButton
391439
{
392440
if (rightButton == _rightButton) { return; }
393441
_rightButton = rightButton;
394-
self.keypadView.rightAccessoryView = rightButton;
442+
443+
if (self.keypadView) {
444+
self.keypadView.rightAccessoryView = rightButton;
445+
}
446+
else {
447+
[self addSubview:_rightButton];
448+
}
395449
}
396450

397451
- (CGFloat)keypadButtonInset

TOPasscodeViewControllerExample.xcodeproj/project.pbxproj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
/* Begin PBXFileReference section */
5353
2205DFB91EDF42A00071BC7F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
5454
221D96E11EDC03FF004314BF /* LocalAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LocalAuthentication.framework; path = System/Library/Frameworks/LocalAuthentication.framework; sourceTree = SDKROOT; };
55+
224E40CF1F3449E100C03A79 /* RevealServer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RevealServer.framework; sourceTree = "<group>"; };
5556
226EFC011EE3FA490033B079 /* SettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsViewController.h; sourceTree = "<group>"; };
5657
226EFC021EE3FA490033B079 /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = "<group>"; };
5758
2271931B1EE3E0D4000324B7 /* TOBlurView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TOBlurView.h; sourceTree = "<group>"; };
@@ -130,6 +131,7 @@
130131
221D96E01EDC03FF004314BF /* Frameworks */ = {
131132
isa = PBXGroup;
132133
children = (
134+
224E40CF1F3449E100C03A79 /* RevealServer.framework */,
133135
2205DFB91EDF42A00071BC7F /* AudioToolbox.framework */,
134136
221D96E11EDC03FF004314BF /* LocalAuthentication.framework */,
135137
);
@@ -286,6 +288,7 @@
286288
22F8069F1ECABB3D0053C94E /* Sources */,
287289
22F806A01ECABB3D0053C94E /* Frameworks */,
288290
22F806A11ECABB3D0053C94E /* Resources */,
291+
224E40D01F344A3B00C03A79 /* Integrate Reveal Server */,
289292
);
290293
buildRules = (
291294
);
@@ -377,6 +380,23 @@
377380
};
378381
/* End PBXResourcesBuildPhase section */
379382

383+
/* Begin PBXShellScriptBuildPhase section */
384+
224E40D01F344A3B00C03A79 /* Integrate Reveal Server */ = {
385+
isa = PBXShellScriptBuildPhase;
386+
buildActionMask = 2147483647;
387+
files = (
388+
);
389+
inputPaths = (
390+
);
391+
name = "Integrate Reveal Server";
392+
outputPaths = (
393+
);
394+
runOnlyForDeploymentPostprocessing = 0;
395+
shellPath = /bin/sh;
396+
shellScript = "export REVEAL_SERVER_FILENAME=\"RevealServer.framework\"\n\n# Update this path to point to the location of RevealServer.framework in your project.\nexport REVEAL_SERVER_PATH=\"${SRCROOT}/${REVEAL_SERVER_FILENAME}\"\n\n# If configuration is not Debug, skip this script.\n[ \"${CONFIGURATION}\" != \"Debug\" ] && exit 0\n\n# If RevealServer.framework exists at the specified path, run code signing script.\nif [ -d \"${REVEAL_SERVER_PATH}\" ]; then\n\"${REVEAL_SERVER_PATH}/Scripts/copy_and_codesign_revealserver.sh\"\nelse\necho \"Reveal Server not loaded: RevealServer.framework could not be found.\"\nfi\n";
397+
};
398+
/* End PBXShellScriptBuildPhase section */
399+
380400
/* Begin PBXSourcesBuildPhase section */
381401
22F8069F1ECABB3D0053C94E /* Sources */ = {
382402
isa = PBXSourcesBuildPhase;
@@ -542,9 +562,18 @@
542562
buildSettings = {
543563
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
544564
DEVELOPMENT_TEAM = 6LF3GMKZAB;
565+
FRAMEWORK_SEARCH_PATHS = (
566+
"$(inherited)",
567+
"$(SRCROOT)",
568+
);
545569
INFOPLIST_FILE = "$(SRCROOT)/TOPasscodeViewControllerExample/Info.plist";
546570
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
547571
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
572+
OTHER_LDFLAGS = (
573+
"-ObjC",
574+
"-weak_framework",
575+
RevealServer,
576+
);
548577
PRODUCT_BUNDLE_IDENTIFIER = co.timoliver.TOPasscodeViewControllerExample;
549578
PRODUCT_NAME = "$(TARGET_NAME)";
550579
TARGETED_DEVICE_FAMILY = "1,2";
@@ -556,9 +585,18 @@
556585
buildSettings = {
557586
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
558587
DEVELOPMENT_TEAM = 6LF3GMKZAB;
588+
FRAMEWORK_SEARCH_PATHS = (
589+
"$(inherited)",
590+
"$(SRCROOT)",
591+
);
559592
INFOPLIST_FILE = "$(SRCROOT)/TOPasscodeViewControllerExample/Info.plist";
560593
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
561594
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
595+
OTHER_LDFLAGS = (
596+
"-ObjC",
597+
"-weak_framework",
598+
RevealServer,
599+
);
562600
PRODUCT_BUNDLE_IDENTIFIER = co.timoliver.TOPasscodeViewControllerExample;
563601
PRODUCT_NAME = "$(TARGET_NAME)";
564602
TARGETED_DEVICE_FAMILY = "1,2";

0 commit comments

Comments
 (0)