@@ -17,10 +17,12 @@ @interface TOPasscodeView ()
1717/* The current layout object used to configure this view */
1818@property (nonatomic , weak ) TOPasscodeViewContentLayout *currentLayout;
1919
20+ /* The main views */
2021@property (nonatomic , strong , readwrite ) UILabel *titleLabel;
21- @property (nonatomic , strong , readwrite ) TOPasscodeKeypadView *keypadView;
2222@property (nonatomic , strong , readwrite ) TOPasscodeInputField *inputField;
23+ @property (nonatomic , strong , readwrite ) TOPasscodeKeypadView *keypadView;
2324
25+ /* The type of passcode we're displaying */
2426@property (nonatomic , assign , readwrite ) TOPasscodeType passcodeType;
2527
2628@end
@@ -77,7 +79,7 @@ - (void)setUp
7779}
7880
7981#pragma mark - View Layout -
80- - (void )layoutSubviews
82+ - (void )verticallyLayoutSubviews
8183{
8284 CGSize viewSize = self.frame .size ;
8385 CGSize midViewSize = (CGSize){self.frame .size .width * 0 .5f , self.frame .size .height * 0 .5f };
@@ -137,6 +139,64 @@ - (void)layoutSubviews
137139 }
138140}
139141
142+ - (void )horizontallyLayoutSubviews
143+ {
144+ CGSize midViewSize = (CGSize){self.frame .size .width * 0 .5f , self.frame .size .height * 0 .5f };
145+ CGRect frame = CGRectZero;
146+
147+ // Work out total height of header content
148+ CGFloat headerHeight = 0 .0f ;
149+ if (self.titleView ) {
150+ headerHeight += self.titleView .frame .size .height ;
151+ headerHeight += self.currentLayout .titleViewBottomSpacing ;
152+ }
153+
154+ headerHeight += self.titleLabel .frame .size .height ;
155+ headerHeight += self.currentLayout .titleLabelBottomSpacing ;
156+
157+ headerHeight += self.inputField .frame .size .height ;
158+
159+ // Set initial Y offset
160+ frame.origin .y = midViewSize.height - (headerHeight * 0 .5f );
161+
162+ // Set frame of title view
163+ if (self.titleView ) {
164+ frame.size = self.titleView .frame .size ;
165+ frame.origin .x = (self.currentLayout .titleHorizontalLayoutWidth - frame.size .width ) * 0 .5f ;
166+ self.titleView .frame = CGRectIntegral (frame);
167+
168+ frame.origin .y += (frame.size .height + self.currentLayout .titleViewBottomSpacing );
169+ }
170+
171+ // Set frame of title label
172+ frame.size = self.titleLabel .frame .size ;
173+ frame.origin .x = (self.currentLayout .titleHorizontalLayoutWidth - frame.size .width ) * 0 .5f ;
174+ self.titleLabel .frame = CGRectIntegral (frame);
175+
176+ frame.origin .y += (frame.size .height + self.currentLayout .titleLabelBottomSpacing );
177+
178+ // Set frame of the input field
179+ frame.size = self.inputField .frame .size ;
180+ frame.origin .x = (self.currentLayout .titleHorizontalLayoutWidth - frame.size .width ) * 0 .5f ;
181+ self.inputField .frame = CGRectIntegral (frame);
182+
183+ // Set the frame of the keypad view
184+ frame.size = self.keypadView .frame .size ;
185+ frame.origin .y = 0 .0f ;
186+ frame.origin .x = self.currentLayout .titleHorizontalLayoutWidth + self.currentLayout .titleHorizontalLayoutSpacing ;
187+ self.keypadView .frame = CGRectIntegral (frame);
188+ }
189+
190+ - (void )layoutSubviews
191+ {
192+ if (self.horizontalLayout ) {
193+ [self horizontallyLayoutSubviews ];
194+ }
195+ else {
196+ [self verticallyLayoutSubviews ];
197+ }
198+ }
199+
140200- (void )sizeToFitSize : (CGSize)size
141201{
142202 CGFloat width = size.width ;
@@ -164,7 +224,7 @@ - (void)sizeToFitSize:(CGSize)size
164224 [self sizeToFit ];
165225}
166226
167- - (void )sizeToFit
227+ - (void )verticalSizeToFit
168228{
169229 CGRect frame = self.frame ;
170230 frame.size .width = 0 .0f ;
@@ -217,6 +277,32 @@ - (void)sizeToFit
217277 self.frame = CGRectIntegral (frame);
218278}
219279
280+ - (void )horizontalSizeToFit
281+ {
282+ CGRect frame = self.frame ;
283+
284+ [self .keypadView sizeToFit ];
285+ [self .inputField sizeToFit ];
286+
287+ frame.size .width = self.currentLayout .titleHorizontalLayoutWidth ;
288+ frame.size .width += self.currentLayout .titleHorizontalLayoutSpacing ;
289+ frame.size .width += self.keypadView .frame .size .width ;
290+
291+ frame.size .height = self.keypadView .frame .size .height ;
292+
293+ self.frame = CGRectIntegral (frame);
294+ }
295+
296+ - (void )sizeToFit
297+ {
298+ if (self.horizontalLayout ) {
299+ [self horizontalSizeToFit ];
300+ }
301+ else {
302+ [self verticalSizeToFit ];
303+ }
304+ }
305+
220306#pragma mark - View Setup -
221307- (void )setUpViewForType : (TOPasscodeType)type
222308{
0 commit comments