@@ -54,23 +54,29 @@ @interface TYAlertView ()
54
54
@property (nonatomic , weak ) UIView *textFeildContentView;
55
55
@property (nonatomic , weak ) NSLayoutConstraint *textFeildTopConstraint;
56
56
@property (nonatomic , strong ) NSMutableArray *textFeilds;
57
+ @property (nonatomic , strong ) NSMutableArray *textFeildSeparateViews;
57
58
58
59
// button content View
59
60
@property (nonatomic , weak ) UIView *buttonContentView;
60
61
@property (nonatomic , strong ) NSMutableArray *buttons;
61
62
@property (nonatomic , strong ) NSMutableArray *actions;
62
63
63
- @property (nonatomic , assign ) CGFloat contentViewSpace;
64
- @property (nonatomic , assign ) CGFloat textLabelSpace;
65
- @property (nonatomic , assign ) CGFloat contentViewEdge;
66
-
67
64
@end
68
65
66
+ #define kContentViewEdge 15
67
+ #define kContentViewSpace 15
68
+
69
+ #define kTextLabelSpace 6
70
+
69
71
#define kButtonTagOffset 1000
72
+ #define kButtonSpace 6
70
73
#define KButtonHeight 44
74
+
71
75
#define kTextFeildOffset 10000
72
- #define kTextFeildHeight 30
73
- #define kTextFeildBorderColor [UIColor colorWithRed: 203 /255.0 green: 203 /255.0 blue: 203 /255.0 alpha: 1 ];
76
+ #define kTextFeildHeight 29
77
+ #define kTextFeildEdge 8
78
+ #define KTextFeildBorderWidth 0.5
79
+
74
80
75
81
@implementation TYAlertView
76
82
@@ -110,16 +116,31 @@ + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message
110
116
return [[self alloc ]initWithTitle:title message: message];
111
117
}
112
118
119
+ #pragma mark - configure
120
+
113
121
- (void )configureProperty
114
122
{
115
- _contentViewSpace = 15 ;
116
- _contentViewEdge = 12 ;
117
- _textLabelSpace = 6 ;
123
+ self.backgroundColor = [UIColor whiteColor ];
124
+ _contentViewSpace = kContentViewSpace ;
125
+
126
+ _textLabelSpace = kTextLabelSpace ;
127
+ _textLabelContentViewEdge = kContentViewEdge ;
128
+
129
+ _buttonHeight = KButtonHeight;
130
+ _buttonSpace = kButtonSpace ;
131
+ _buttonContentViewEdge = kContentViewEdge ;
132
+
133
+ _textFeildHeight = kTextFeildHeight ;
134
+ _textFeildEdge = kTextFeildEdge ;
135
+ _textFeildorderWidth = KTextFeildBorderWidth;
136
+ _textFeildContentViewEdge = kContentViewEdge ;
137
+
138
+ _textFieldBorderColor = [UIColor colorWithRed: 203 /255.0 green: 203 /255.0 blue: 203 /255.0 alpha: 1 ];
139
+ _textFieldBackgroudColor = [UIColor whiteColor ];
140
+ _textFieldFont = [UIFont systemFontOfSize: 14 ];
118
141
119
142
_buttons = [NSMutableArray array ];
120
143
_actions = [NSMutableArray array ];
121
-
122
- _textFieldBorderColor = kTextFeildBorderColor ;
123
144
}
124
145
125
146
#pragma mark - add contentview
@@ -183,7 +204,7 @@ - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textFeild))c
183
204
184
205
UITextField *textField = [[UITextField alloc ]init];
185
206
textField.tag = kTextFeildOffset + _textFeilds.count ;
186
- textField.backgroundColor = [UIColor whiteColor ] ;
207
+ textField.font = _textFieldFont ;
187
208
textField.translatesAutoresizingMaskIntoConstraints = NO ;
188
209
189
210
if (configurationHandler) {
@@ -193,6 +214,17 @@ - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textFeild))c
193
214
[_textFeildContentView addSubview: textField];
194
215
[_textFeilds addObject: textField];
195
216
217
+ if (_textFeilds.count > 1 ) {
218
+ if (_textFeildSeparateViews == nil ) {
219
+ _textFeildSeparateViews = [NSMutableArray array ];
220
+ }
221
+ UIView *separateView = [[UIView alloc ]init];
222
+ separateView.backgroundColor = _textFieldBorderColor;
223
+ separateView.translatesAutoresizingMaskIntoConstraints = NO ;
224
+ [_textFeildContentView addSubview: separateView];
225
+ [_textFeildSeparateViews addObject: separateView];
226
+ }
227
+
196
228
[self layoutTextFeilds ];
197
229
}
198
230
@@ -203,20 +235,20 @@ - (void)layoutContentViews
203
235
// textContentView
204
236
_textContentView.translatesAutoresizingMaskIntoConstraints = NO ;
205
237
206
- [self addConstarintWithView: _textContentView topView: self leftView: self bottomView: nil rightView: self edageInset: UIEdgeInsetsMake (_contentViewEdge, _contentViewEdge , 0 , -_contentViewEdge )];
238
+ [self addConstarintWithView: _textContentView topView: self leftView: self bottomView: nil rightView: self edageInset: UIEdgeInsetsMake (_contentViewSpace, _textLabelContentViewEdge , 0 , -_textLabelContentViewEdge )];
207
239
208
240
// textFeildContentView
209
241
_textFeildContentView.translatesAutoresizingMaskIntoConstraints = NO ;
210
242
_textFeildTopConstraint = [self addConstarintWithTopView: _textContentView toBottomView: _textFeildContentView constarint: 0 ];
211
243
212
- [self addConstarintWithView: _textFeildContentView topView: nil leftView: self bottomView: nil rightView: self edageInset: UIEdgeInsetsMake (0 , _contentViewEdge , 0 , -_contentViewEdge )];
244
+ [self addConstarintWithView: _textFeildContentView topView: nil leftView: self bottomView: nil rightView: self edageInset: UIEdgeInsetsMake (0 , _textFeildContentViewEdge , 0 , -_textFeildContentViewEdge )];
213
245
214
246
// buttonContentView
215
247
_buttonContentView.translatesAutoresizingMaskIntoConstraints = NO ;
216
248
217
249
[self addConstarintWithTopView: _textFeildContentView toBottomView: _buttonContentView constarint: _contentViewSpace];
218
250
219
- [self addConstarintWithView: _buttonContentView topView: nil leftView: self bottomView: self rightView: self edageInset: UIEdgeInsetsMake (0 , _contentViewEdge , -_contentViewEdge , -_contentViewEdge )];
251
+ [self addConstarintWithView: _buttonContentView topView: nil leftView: self bottomView: self rightView: self edageInset: UIEdgeInsetsMake (0 , _buttonContentViewEdge , -_contentViewSpace , -_buttonContentViewEdge )];
220
252
}
221
253
222
254
- (void )layoutTextLabels
@@ -234,12 +266,12 @@ - (void)layoutButtons
234
266
UIButton *button = _buttons.lastObject ;
235
267
if (_buttons.count == 1 ) {
236
268
[button addConstraintToView: _buttonContentView edageInset: UIEdgeInsetsZero];
237
- [button addConstarintWidth: 0 height: KButtonHeight ];
269
+ [button addConstarintWidth: 0 height: _buttonHeight ];
238
270
}else if (_buttons.count == 2 ) {
239
271
UIButton *firstButton = _buttons.firstObject ;
240
272
[_buttonContentView removeConstraintWithView: firstButton attribte: NSLayoutAttributeRight];
241
273
[_buttonContentView addConstarintWithView: button topView: _buttonContentView leftView: nil bottomView: nil rightView: _buttonContentView edageInset: UIEdgeInsetsZero];
242
- [_buttonContentView addConstarintWithLeftView: firstButton toRightView: button constarint: _textLabelSpace ];
274
+ [_buttonContentView addConstarintWithLeftView: firstButton toRightView: button constarint: _buttonSpace ];
243
275
[_buttonContentView addConstarintEqualWithView: button widthToView: firstButton heightToView: firstButton];
244
276
}else {
245
277
if (_buttons.count == 3 ) {
@@ -249,12 +281,12 @@ - (void)layoutButtons
249
281
[_buttonContentView removeConstraintWithView: firstBtn attribte: NSLayoutAttributeBottom];
250
282
[_buttonContentView removeConstraintWithView: secondBtn attribte: NSLayoutAttributeTop];
251
283
[_buttonContentView addConstarintWithView: firstBtn topView: nil leftView: nil bottomView: 0 rightView: _buttonContentView edageInset: UIEdgeInsetsZero];
252
- [_buttonContentView addConstarintWithTopView: firstBtn toBottomView: secondBtn constarint: _textLabelSpace ];
284
+ [_buttonContentView addConstarintWithTopView: firstBtn toBottomView: secondBtn constarint: _buttonSpace ];
253
285
254
286
}
255
287
UIButton *lastSecondBtn = _buttons[_buttons.count-2 ];
256
288
[_buttonContentView removeConstraintWithView: lastSecondBtn attribte: NSLayoutAttributeBottom];
257
- [_buttonContentView addConstarintWithTopView: lastSecondBtn toBottomView: button constarint: _textLabelSpace ];
289
+ [_buttonContentView addConstarintWithTopView: lastSecondBtn toBottomView: button constarint: _buttonSpace ];
258
290
[_buttonContentView addConstarintWithView: button topView: nil leftView: _buttonContentView bottomView: _buttonContentView rightView: _buttonContentView edageInset: UIEdgeInsetsZero];
259
291
[_buttonContentView addConstarintEqualWithView: button widthToView: nil heightToView: lastSecondBtn];
260
292
}
@@ -266,28 +298,34 @@ - (void)layoutTextFeilds
266
298
267
299
if (_textFeilds.count == 1 ) {
268
300
// setup textFeildContentView
269
- _textFeildContentView.backgroundColor = _textFieldBorderColor ;
301
+ _textFeildContentView.backgroundColor = _textFieldBackgroudColor ;
270
302
_textFeildContentView.layer .masksToBounds = YES ;
271
303
_textFeildContentView.layer .cornerRadius = 4 ;
272
- _textFeildContentView.layer .borderWidth = 0.5 ;
304
+ _textFeildContentView.layer .borderWidth = _textFeildorderWidth ;
273
305
_textFeildContentView.layer .borderColor = _textFieldBorderColor.CGColor ;
274
306
_textFeildTopConstraint.constant = -_contentViewSpace;
275
- [textFeild addConstraintToView: _textFeildContentView edageInset: UIEdgeInsetsZero ];
276
- [textFeild addConstarintWidth: 0 height: kTextFeildHeight ];
307
+ [textFeild addConstraintToView: _textFeildContentView edageInset: UIEdgeInsetsMake (_textFeildorderWidth, _textFeildEdge, -_textFeildorderWidth, -_textFeildEdge) ];
308
+ [textFeild addConstarintWidth: 0 height: _textFeildHeight ];
277
309
}else {
278
- UITextField *lastSecondTextFeild = _textFeilds[_textFeilds.count-2 ];
310
+ // textFeild
311
+ UITextField *lastSecondTextFeild = _textFeilds[_textFeilds.count - 2 ];
279
312
[_textFeildContentView removeConstraintWithView: lastSecondTextFeild attribte: NSLayoutAttributeBottom];
280
- [_textFeildContentView addConstarintWithTopView: lastSecondTextFeild toBottomView: textFeild constarint: 0.5 ];
281
- [_textFeildContentView addConstarintWithView: textFeild topView: nil leftView: _textFeildContentView bottomView: _textFeildContentView rightView: _textFeildContentView edageInset: UIEdgeInsetsZero ];
313
+ [_textFeildContentView addConstarintWithTopView: lastSecondTextFeild toBottomView: textFeild constarint: _textFeildorderWidth ];
314
+ [_textFeildContentView addConstarintWithView: textFeild topView: nil leftView: _textFeildContentView bottomView: _textFeildContentView rightView: _textFeildContentView edageInset: UIEdgeInsetsMake ( 0 , _textFeildEdge, -_textFeildorderWidth, -_textFeildEdge) ];
282
315
[_textFeildContentView addConstarintEqualWithView: textFeild widthToView: nil heightToView: lastSecondTextFeild];
316
+
317
+ // separateview
318
+ UIView *separateView = _textFeildSeparateViews[_textFeilds.count - 2 ];
319
+ [_textFeildContentView addConstarintWithView: separateView topView: nil leftView: _textFeildContentView bottomView: nil rightView: _textFeildContentView edageInset: UIEdgeInsetsZero];
320
+ [_textFeildContentView addConstarintWithTopView: separateView toBottomView: textFeild constarint: 0 ];
321
+ [separateView addConstarintWidth: 0 height: _textFeildorderWidth];
283
322
}
284
323
}
285
324
286
325
#pragma mark - action
287
326
288
327
- (void )actionButtonClicked : (UIButton *)button
289
328
{
290
- NSLog (@" actionButtonClicked tag:%ld " ,button.tag );
291
329
TYAlertAction *action = _actions[button.tag - kButtonTagOffset ];
292
330
293
331
if (action.handler ) {
0 commit comments