@@ -17,10 +17,12 @@ @interface TOPasscodeView ()
17
17
/* The current layout object used to configure this view */
18
18
@property (nonatomic , weak ) TOPasscodeViewContentLayout *currentLayout;
19
19
20
+ /* The main views */
20
21
@property (nonatomic , strong , readwrite ) UILabel *titleLabel;
21
- @property (nonatomic , strong , readwrite ) TOPasscodeKeypadView *keypadView;
22
22
@property (nonatomic , strong , readwrite ) TOPasscodeInputField *inputField;
23
+ @property (nonatomic , strong , readwrite ) TOPasscodeKeypadView *keypadView;
23
24
25
+ /* The type of passcode we're displaying */
24
26
@property (nonatomic , assign , readwrite ) TOPasscodeType passcodeType;
25
27
26
28
@end
@@ -77,7 +79,7 @@ - (void)setUp
77
79
}
78
80
79
81
#pragma mark - View Layout -
80
- - (void )layoutSubviews
82
+ - (void )verticallyLayoutSubviews
81
83
{
82
84
CGSize viewSize = self.frame .size ;
83
85
CGSize midViewSize = (CGSize){self.frame .size .width * 0 .5f , self.frame .size .height * 0 .5f };
@@ -137,6 +139,64 @@ - (void)layoutSubviews
137
139
}
138
140
}
139
141
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
+
140
200
- (void )sizeToFitSize : (CGSize)size
141
201
{
142
202
CGFloat width = size.width ;
@@ -164,7 +224,7 @@ - (void)sizeToFitSize:(CGSize)size
164
224
[self sizeToFit ];
165
225
}
166
226
167
- - (void )sizeToFit
227
+ - (void )verticalSizeToFit
168
228
{
169
229
CGRect frame = self.frame ;
170
230
frame.size .width = 0 .0f ;
@@ -217,6 +277,32 @@ - (void)sizeToFit
217
277
self.frame = CGRectIntegral (frame);
218
278
}
219
279
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
+
220
306
#pragma mark - View Setup -
221
307
- (void )setUpViewForType : (TOPasscodeType)type
222
308
{
0 commit comments