1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
//
// TAPCustomTextFieldView.m
// TapTalk
//
// Created by Dominic Vedericho on 01/04/19.
// Copyright © 2019 Moselo. All rights reserved.
//
#import "TAPCustomTextFieldView.h"
#import "TAPCustomPhoneNumberPickerView.h"
@interface TAPCustomTextFieldView () <UITextFieldDelegate, TAPCustomPhoneNumberPickerViewDelegate>
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *infoDescriptionLabel;
@property (strong, nonatomic) UIImageView *iconErrorInFoImageView;
@property (strong, nonatomic) UILabel *errorInfoLabel;
@property (strong, nonatomic) UIView *containerView;
@property (strong, nonatomic) UIView *shadowView;
@property (strong, nonatomic) UIView *containerSeparatorView;
@property (strong, nonatomic) UIImageView *passwordShowImageView;
@property (strong, nonatomic) UIButton *showPasswordButton;
@property (strong, nonatomic) TAPCustomPhoneNumberPickerView *phoneNumberPickerView;
@property (nonatomic) BOOL isError;
@property (nonatomic) BOOL isActive;
- (void)setInfoDescriptionText:(NSString *)string;
- (void)showPasswordButtonDidTapped;
- (void)showShowPasswordButton:(BOOL)show;
@end
@implementation TAPCustomTextFieldView
#pragma mark - Lifecycle
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
UIFont *formLabelFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormLabel];
UIColor *formLabelColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorFormLabel];
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, 0.0f, CGRectGetWidth(self.frame) - 16.0f - 16.0f, 22.0f)];
self.titleLabel.font = formLabelFont;
self.titleLabel.textColor = formLabelColor;
[self addSubview:self.titleLabel];
_containerView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMaxY(self.titleLabel.frame) + 8.0f, CGRectGetWidth(self.frame) - 16.0f - 16.0f, 50.0f)];
self.containerView.backgroundColor = [UIColor whiteColor];
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive].CGColor;
self.containerView.layer.cornerRadius = 8.0f;
self.containerView.layer.borderWidth = 1.0f;
_phoneNumberPickerView = [[TAPCustomPhoneNumberPickerView alloc] initWithFrame:CGRectMake(0.0f, CGRectGetMaxY(self.titleLabel.frame) + 8.0f, CGRectGetWidth(self.frame), 50.0f)];
self.phoneNumberPickerView.delegate = self;
[self.phoneNumberPickerView setCountryCodePhoneNumberWithData:[TAPCountryModel new]];
_shadowView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.containerView.frame), CGRectGetMinY(self.containerView.frame), CGRectGetWidth(self.containerView.frame), 50.0f)];
self.shadowView.backgroundColor = [UIColor whiteColor];
self.shadowView.layer.cornerRadius = 8.0f;
self.shadowView.layer.shadowRadius = 5.0f;
self.shadowView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.shadowView.layer.shadowOpacity = 1.0f;
self.shadowView.layer.masksToBounds = NO;
self.shadowView.alpha = 0.0f;
[self addSubview:self.shadowView];
[self addSubview:self.containerView];
[self addSubview:self.phoneNumberPickerView];
_containerSeparatorView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.containerView.frame) - 50.0f, 0.0f, 1.0f, CGRectGetHeight(self.containerView.frame))];
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive];
[self.containerView addSubview:self.containerSeparatorView];
_passwordShowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.containerSeparatorView.frame) + 15.0f, 15.0f, 20.0f, 20.0f)];
self.passwordShowImageView.image = [UIImage imageNamed:@"TAPIconShowPassword" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.passwordShowImageView.image = [self.passwordShowImageView.image setImageTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorIconViewPasswordInactive]];
[self.containerView addSubview:self.passwordShowImageView];
_showPasswordButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.containerSeparatorView.frame), 0.0f, 50.0f, 50.0f)];
[self.showPasswordButton addTarget:self action:@selector(showPasswordButtonDidTapped) forControlEvents:UIControlEventTouchUpInside];
[self.containerView addSubview:self.showPasswordButton];
UIFont *textFieldFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormTextField];
UIColor *textFieldColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorFormTextField];
_textField = [[UITextField alloc] initWithFrame:CGRectMake(16.0f, 0.0f, CGRectGetWidth(self.containerView.frame) - 16.0f - 16.0f, CGRectGetHeight(self.containerView.frame))];
self.textField.delegate = self;
[self.textField setTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldCursor]];
self.textField.textColor = textFieldColor;
self.textField.font = textFieldFont;
[self.containerView addSubview:self.textField];
UIFont *formDescriptionLabelBodyFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormDescriptionLabel];
UIColor *formDescriptionLabelBodyColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorFormDescriptionLabel];
_infoDescriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMaxY(self.containerView.frame) + 8.0f, CGRectGetWidth(self.frame) - 16.0f - 16.0f, 0.0f)];
self.infoDescriptionLabel.font = formDescriptionLabelBodyFont;
self.infoDescriptionLabel.textColor = formDescriptionLabelBodyColor;
self.infoDescriptionLabel.numberOfLines = 0;
[self addSubview:self.infoDescriptionLabel];
_iconErrorInFoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMaxY(self.infoDescriptionLabel.frame) + 8.0f, 16.0f, 0.0f)]; //AS NOTE - height will be resized
self.iconErrorInFoImageView.image = [UIImage imageNamed:@"TAPIconRedAlertCircle" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.iconErrorInFoImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:self.iconErrorInFoImageView];
UIFont *formErrorInfoLabelFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormErrorInfoLabel];
UIColor *formErrorInfoLabelColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorFormErrorInfoLabel];
_errorInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.iconErrorInFoImageView.frame) + 4.0f, CGRectGetMinY(self.iconErrorInFoImageView.frame), CGRectGetWidth(self.frame) - 16.0f - 16.0f, 0.0f)];
self.errorInfoLabel.font = formErrorInfoLabelFont;
self.errorInfoLabel.textColor = formErrorInfoLabelColor;
self.errorInfoLabel.numberOfLines = 0;
[self addSubview:self.errorInfoLabel];
}
return self;
}
#pragma mark - Delegate
#pragma mark UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextField:shouldChangeCharactersInRange:replacementString:)]) {
return [self.delegate customTextFieldViewTextField:textField shouldChangeCharactersInRange:range replacementString:string];
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextFieldShouldReturn:)]) {
return [self.delegate customTextFieldViewTextFieldShouldReturn:textField];
}
return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self setAsActive:YES animated:YES];
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextFieldShouldBeginEditing:)]) {
return [self.delegate customTextFieldViewTextFieldShouldBeginEditing:textField];
}
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextFieldDidBeginEditing:)]) {
[self.delegate customTextFieldViewTextFieldDidBeginEditing:textField];
}
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
[self setAsActive:NO animated:YES];
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextFieldShouldEndEditing:)]) {
return [self.delegate customTextFieldViewTextFieldShouldEndEditing:textField];
}
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextFieldDidEndEditing:)]) {
[self.delegate customTextFieldViewTextFieldDidEndEditing:textField];
}
}
- (BOOL)textFieldShouldClear:(UITextField *)textField {
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextFieldShouldClear:)]) {
return [self.delegate customTextFieldViewTextFieldShouldClear:textField];
}
return YES;
}
#pragma mark TAPCustomPhoneNumberPickerView
- (void)customPhoneNumberPickerViewDidTappedDoneKeyboardButton {
}
- (BOOL)customPhoneNumberPickerViewTextField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
self.textField.text = newText;
if ([self.delegate respondsToSelector:@selector(customTextFieldViewTextField:shouldChangeCharactersInRange:replacementString:)]) {
return [self.delegate customTextFieldViewTextField:textField shouldChangeCharactersInRange:range replacementString:string];
}
return YES;
}
- (BOOL)customPhoneNumberPickerViewTextFieldShouldReturn:(UITextField *)textField {
return YES;
}
- (BOOL)customPhoneNumberPickerViewTextFieldShouldBeginEditing:(UITextField *)textField {
return YES;
}
- (void)customPhoneNumberPickerViewTextFieldDidBeginEditing:(UITextField *)textField {
}
- (BOOL)customPhoneNumberPickerViewTextFieldShouldEndEditing:(UITextField *)textField {
return YES;
}
- (void)customPhoneNumberPickerViewTextFieldDidEndEditing:(UITextField *)textField {
}
- (BOOL)customPhoneNumberPickerViewTextFieldShouldClear:(UITextField *)textField {
return YES;
}
#pragma mark - Custom Method
- (void)setTapCustomTextFieldViewType:(TAPCustomTextFieldViewType)tapCustomTextFieldViewType {
_tapCustomTextFieldViewType = tapCustomTextFieldViewType;
NSString *placeholderString = @"";
if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeFullName) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Full Name", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"e.g Bernama", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.textField.alpha = 0.4f;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeUsername) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Username", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:NSLocalizedStringFromTableInBundle(@"Username is always required.\nMust be between 4-32 characters.\nCan only contain a-z, 0-9, underscores, and dot.\nCan't start with number or underscore or dot.\nCan't end with underscore or dot.\nCan't contain consecutive underscores, consecutive dot, underscore followed with dot, and otherwise.", nil, [TAPUtil currentBundle], @"")];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"e.g user1234", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeUsernameWithoutDescription) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Username", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"Enter username", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.alpha = 0.4f;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeMobileNumber) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Mobile Number", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = @"";
self.textField.placeholder = placeholderString;
self.containerView.alpha = 0.0f;
self.phoneNumberPickerView.alpha = 1.0f;
[self showShowPasswordButton:NO];
[self.phoneNumberPickerView setAsDisabled:YES];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeEmailOptional) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Email Address Optional", nil, [TAPUtil currentBundle], @"");
UIFont *formDescriptionFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormDescriptionLabel];
NSString *optionalString = NSLocalizedStringFromTableInBundle(@"Optional", nil, [TAPUtil currentBundle], @"");
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
[attributedString addAttribute:NSFontAttributeName
value:formDescriptionFont
range:[self.titleLabel.text rangeOfString:optionalString]];
self.titleLabel.attributedText = attributedString;
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeEmailAddress;
self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
placeholderString = NSLocalizedStringFromTableInBundle(@"e.g example@work.com", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.textField.alpha = 0.4f;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeEmail) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Email Address", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeEmailAddress;
self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
placeholderString = NSLocalizedStringFromTableInBundle(@"e.g example@work.com", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypePasswordOptional) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Password Optional", nil, [TAPUtil currentBundle], @"");
UIFont *formDescriptionFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormDescriptionLabel];
NSString *optionalString = NSLocalizedStringFromTableInBundle(@"Optional", nil, [TAPUtil currentBundle], @"");
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
[attributedString addAttribute:NSFontAttributeName
value:formDescriptionFont
range:[self.titleLabel.text rangeOfString:optionalString]];
self.titleLabel.attributedText = attributedString;
[self setInfoDescriptionText:NSLocalizedStringFromTableInBundle(@"Password must contain at least one lowercase, uppercase, special character, and a number.", nil, [TAPUtil currentBundle], @"")];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"Insert Password", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.textField.secureTextEntry = YES;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:YES];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeReTypePassword) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Retype Password", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"Retype Password", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.textField.secureTextEntry = YES;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:YES];
}
else if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeGroupName) {
self.titleLabel.text = NSLocalizedStringFromTableInBundle(@"Group Name", nil, [TAPUtil currentBundle], @"");
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"Insert Name", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
if (tapCustomTextFieldViewType == TAPCustomTextFieldViewTypeShareExtensionAddMessage) {
self.titleLabel.text = @"";
self.titleLabel.frame = CGRectMake(16.0f, 0.0f, CGRectGetWidth(self.frame) - 16.0f - 16.0f, 0.0f); //AS NOTE - BECAUSE USED in SHARE EXTENSION, so hide
self.containerView.frame = CGRectMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMaxY(self.titleLabel.frame), CGRectGetWidth(self.frame) - 16.0f - 16.0f, 50.0f);
[self setInfoDescriptionText:@""];
[self setErrorInfoText:@""];
self.textField.keyboardType = UIKeyboardTypeDefault;
placeholderString = NSLocalizedStringFromTableInBundle(@"Add message...", nil, [TAPUtil currentBundle], @"");
self.textField.placeholder = placeholderString;
self.containerView.alpha = 1.0f;
self.phoneNumberPickerView.alpha = 0.0f;
[self showShowPasswordButton:NO];
}
//AS NOTE - `titleLabel` ADDED LETTER SPACING
// NSMutableAttributedString *titleLabelAttributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
// NSMutableDictionary *titleLabelAttributesDictionary = [NSMutableDictionary dictionary];
// CGFloat titleLabelLetterSpacing = -0.2f;
// [titleLabelAttributesDictionary setObject:@(titleLabelLetterSpacing) forKey:NSKernAttributeName];
// [titleLabelAttributedString addAttributes:titleLabelAttributesDictionary
// range:NSMakeRange(0, [self.titleLabel.text length])];
// self.titleLabel.attributedText = titleLabelAttributedString;
//TEXTFIELD PLACEHOLDER
UIColor *textFieldPlaceholderColor = [[TAPUtil getColor:TAP_COLOR_TEXT_DARK] colorWithAlphaComponent:0.4f];
UIFont *textFieldPlaceholderFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontFormTextField];
//AS NOTE - 1TEXTFIELD PLACEHOLDER1 ADDED LETTER SPACING
NSMutableAttributedString *textFieldPlaceholderAttributedString = [[NSMutableAttributedString alloc] initWithString:placeholderString];
NSMutableDictionary *textFieldPlaceholderAttributesDictionary = [NSMutableDictionary dictionary];
CGFloat textFieldPlaceholderLetterSpacing = -0.3f;
[textFieldPlaceholderAttributesDictionary setObject:@(textFieldPlaceholderLetterSpacing) forKey:NSKernAttributeName];
[textFieldPlaceholderAttributedString addAttributes:textFieldPlaceholderAttributesDictionary
range:NSMakeRange(0, [placeholderString length])];
[textFieldPlaceholderAttributedString addAttribute:NSForegroundColorAttributeName
value:textFieldPlaceholderColor
range:NSMakeRange(0, [placeholderString length])];
self.textField.attributedPlaceholder = textFieldPlaceholderAttributedString;
}
- (void)setInfoDescriptionText:(NSString *)string {
string = [TAPUtil nullToEmptyString:string];
self.infoDescriptionLabel.text = string;
NSMutableAttributedString *infoDescriptionLabelAttributedString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableDictionary *infoDescriptionLabelAttributesDictionary = [NSMutableDictionary dictionary];
CGFloat infoDescriptionLabelLetterSpacing = -0.2f;
[infoDescriptionLabelAttributesDictionary setObject:@(infoDescriptionLabelLetterSpacing) forKey:NSKernAttributeName];
[infoDescriptionLabelAttributedString addAttributes:infoDescriptionLabelAttributesDictionary
range:NSMakeRange(0, [string length])];
self.infoDescriptionLabel.attributedText = infoDescriptionLabelAttributedString;
CGFloat ySpacing = 8.0f;
if ([string isEqualToString:@""] || string == nil) {
ySpacing = 0.0f;
}
CGSize size = [self.infoDescriptionLabel sizeThatFits:CGSizeMake(CGRectGetWidth(self.infoDescriptionLabel.frame), CGFLOAT_MAX)];
self.infoDescriptionLabel.frame = CGRectMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMaxY(self.containerView.frame) + ySpacing, CGRectGetWidth(self.infoDescriptionLabel.frame), size.height);
CGFloat errorInfoYSpacing = 8.0f;
if ([self.errorInfoLabel.text isEqualToString:@""] || self.errorInfoLabel.text == nil) {
errorInfoYSpacing = 0.0f;
}
self.iconErrorInFoImageView.frame = CGRectMake(CGRectGetMinX(self.iconErrorInFoImageView.frame), CGRectGetMaxY(self.infoDescriptionLabel.frame) + errorInfoYSpacing, CGRectGetWidth(self.iconErrorInFoImageView.frame), CGRectGetHeight(self.iconErrorInFoImageView.frame));
self.errorInfoLabel.frame = CGRectMake(CGRectGetMinX(self.errorInfoLabel.frame), CGRectGetMinY(self.iconErrorInFoImageView.frame), CGRectGetWidth(self.errorInfoLabel.frame), CGRectGetHeight(self.errorInfoLabel.frame));
}
- (void)setErrorInfoText:(NSString *)string {
self.errorInfoLabel.text = string;
CGFloat ySpacing = 8.0f;
if ([string isEqualToString:@""] || string == nil) {
ySpacing = 0.0f;
}
CGFloat heightIconErrorInfoImage = 16.0f;
if ([string isEqualToString:@""]) {
heightIconErrorInfoImage = 0.0f;
}
self.iconErrorInFoImageView.frame = CGRectMake(CGRectGetMinX(self.iconErrorInFoImageView.frame), CGRectGetMaxY(self.infoDescriptionLabel.frame) + ySpacing, CGRectGetWidth(self.iconErrorInFoImageView.frame), heightIconErrorInfoImage);
CGSize size = [self.errorInfoLabel sizeThatFits:CGSizeMake(CGRectGetWidth(self.errorInfoLabel.frame), CGFLOAT_MAX)];
self.errorInfoLabel.frame = CGRectMake(CGRectGetMinX(self.errorInfoLabel.frame), CGRectGetMinY(self.iconErrorInFoImageView.frame), CGRectGetWidth(self.errorInfoLabel.frame), size.height);
}
- (CGFloat)getTextFieldHeight {
return CGRectGetMaxY(self.errorInfoLabel.frame);
}
- (void)setAsActive:(BOOL)active animated:(BOOL)animated {
_isActive = active;
if (self.isError) {
return;
}
if (animated) {
if (active) {
[UIView animateWithDuration:0.2f animations:^{
self.shadowView.alpha = 1.0f;
self.shadowView.layer.shadowColor = [[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive] colorWithAlphaComponent:0.24f].CGColor;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderActive].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderActive];
}];
}
else {
[UIView animateWithDuration:0.2f animations:^{
self.shadowView.alpha = 0.0f;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive];
}];
}
}
else {
if (active) {
self.shadowView.alpha = 1.0f;
self.shadowView.layer.shadowColor = [[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive] colorWithAlphaComponent:0.24f].CGColor;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderActive].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderActive];
}
else {
self.shadowView.alpha = 0.0f;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive];
}
}
}
- (void)setAsEnabled:(BOOL)enabled {
UIColor *textFieldColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorFormTextField];
UIColor *textFieldPlaceholderColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorFormTextFieldPlaceholder];
if (enabled) {
self.textField.textColor = textFieldColor;
self.textField.userInteractionEnabled = YES;
}
else {
self.textField.textColor = textFieldPlaceholderColor;
self.textField.userInteractionEnabled = NO;
self.containerView.backgroundColor = [[TAPUtil getColor:TAP_COLOR_TEXT_DARK] colorWithAlphaComponent:0.1f];
}
}
- (void)setAsError:(BOOL)error animated:(BOOL)animated {
_isError = error;
if (self.isActive && !error) {
[self setAsActive:YES animated:animated];
return;
}
if (animated) {
if (error) {
[UIView animateWithDuration:0.2f animations:^{
self.shadowView.alpha = 0.0f;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderError].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderError];
}];
}
else {
[UIView animateWithDuration:0.2f animations:^{
self.shadowView.alpha = 0.0f;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive];
}];
}
}
else {
if (error) {
self.shadowView.alpha = 0.0f;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderError].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderError];
}
else {
self.shadowView.alpha = 0.0f;
self.containerView.layer.borderColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive].CGColor;
self.containerSeparatorView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorTextFieldBorderInactive];
}
}
}
- (void)showPasswordButtonDidTapped {
if (self.textField.isSecureTextEntry) {
self.textField.secureTextEntry = NO;
self.passwordShowImageView.image = [UIImage imageNamed:@"TAPIconShowPassword" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.passwordShowImageView.image = [self.passwordShowImageView.image setImageTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorIconViewPasswordActive]];
}
else {
self.textField.secureTextEntry = YES;
self.passwordShowImageView.image = [UIImage imageNamed:@"TAPIconShowPassword" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.passwordShowImageView.image = [self.passwordShowImageView.image setImageTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorIconViewPasswordInactive]];
}
}
- (void)showShowPasswordButton:(BOOL)show {
if (show) {
self.containerSeparatorView.alpha = 1.0f;
self.passwordShowImageView.alpha = 1.0f;
self.showPasswordButton.alpha = 1.0f;
self.textField.frame = CGRectMake(CGRectGetMinX(self.textField.frame), CGRectGetMinY(self.textField.frame), CGRectGetWidth(self.containerView.frame) - CGRectGetWidth(self.showPasswordButton.frame) - 16.0f, CGRectGetHeight(self.textField.frame));
}
else {
self.containerSeparatorView.alpha = 0.0f;
self.passwordShowImageView.alpha = 0.0f;
self.showPasswordButton.alpha = 0.0f;
self.textField.frame = CGRectMake(CGRectGetMinX(self.textField.frame), CGRectGetMinY(self.textField.frame), CGRectGetWidth(self.containerView.frame) - 16.0f - 16.0f, CGRectGetHeight(self.textField.frame));
}
}
- (NSString *)getText {
return self.textField.text;
}
- (void)setPhoneNumber:(NSString *)phoneNumber country:(TAPCountryModel *)country {
//remove all characters
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];
NSString *countryCallingCode = country.countryCallingCode;
countryCallingCode = [TAPUtil nullToEmptyString:countryCallingCode];
if ([phoneNumber hasPrefix:countryCallingCode] && ![countryCallingCode isEqualToString:@""]) {
phoneNumber = [phoneNumber stringByReplacingCharactersInRange:NSMakeRange(0, [country.countryCallingCode length]) withString:@""];
}
[self.phoneNumberPickerView setCountryCodePhoneNumberWithData:country];
self.phoneNumberPickerView.phoneNumberTextField.text = phoneNumber;
self.textField.text = phoneNumber;
}
- (void)setTextFieldWithData:(NSString *)dataString {
self.textField.text = dataString;
}
@end