wxr
2020-07-06 23c075a9c27946773feccf05abc90489a6bf5203
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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
//
//  ZJPickerView.m
//  ZJPickerView <https://github.com/Abnerzj/ZJPickerView>
//
//  Created by Abnerzj on 2018/1/12.
//  Copyright © 2017年 Abnerzj. All rights reserved.
//
//  This source code is licensed under the MIT-style license found in the
//  LICENSE file in the root directory of this source tree.
//
 
#import "ZJPickerView.h"
#import "HDLUtlisXM.h"
 
// content: NSString type
NSString * const ZJPickerViewPropertyCanceBtnTitleKey = @"ZJPickerViewPropertyCanceBtnTitleKey";
NSString * const ZJPickerViewPropertySureBtnTitleKey = @"ZJPickerViewPropertySureBtnTitleKey";
NSString * const ZJPickerViewPropertyTipLabelTextKey = @"ZJPickerViewPropertyTipLabelTextKey";
NSString * const ZJPickerViewPropertyDividedSymbolKey = @"ZJPickerViewPropertyDividedSymbolKey";
 
// color: UIColor type
NSString * const ZJPickerViewPropertyCanceBtnTitleColorKey = @"ZJPickerViewPropertyCanceBtnTitleColorKey";
NSString * const ZJPickerViewPropertySureBtnTitleColorKey = @"ZJPickerViewPropertySureBtnTitleColorKey";
NSString * const ZJPickerViewPropertyTipLabelTextColorKey = @"ZJPickerViewPropertyTipLabelTextColorKey";
NSString * const ZJPickerViewPropertyLineViewBackgroundColorKey = @"ZJPickerViewPropertyLineViewBackgroundColorKey";
 
// font: UIFont type
NSString * const ZJPickerViewPropertyCanceBtnTitleFontKey = @"ZJPickerViewPropertyCanceBtnTitleFontKey";
NSString * const ZJPickerViewPropertySureBtnTitleFontKey = @"ZJPickerViewPropertySureBtnTitleFontKey";
NSString * const ZJPickerViewPropertyTipLabelTextFontKey = @"ZJPickerViewPropertyTipLabelTextFontKey";
 
// pickerView:
// CGFloat type
NSString * const ZJPickerViewPropertyPickerViewHeightKey = @"ZJPickerViewPropertyPickerViewHeightKey";
NSString * const ZJPickerViewPropertyOneComponentRowHeightKey = @"ZJPickerViewPropertyOneComponentRowHeightKey";
// NSDictionary type
NSString * const ZJPickerViewPropertySelectRowTitleAttrKey = @"ZJPickerViewPropertySelectRowTitleAttrKey";
NSString * const ZJPickerViewPropertyUnSelectRowTitleAttrKey = @"ZJPickerViewPropertyUnSelectRowTitleAttrKey";
// UIColor type
NSString * const ZJPickerViewPropertySelectRowLineBackgroundColorKey = @"ZJPickerViewPropertySelectRowLineBackgroundColorKey";
 
// other:
// BOOL type
NSString * const ZJPickerViewPropertyIsTouchBackgroundHideKey = @"ZJPickerViewPropertyIsTouchBackgroundHideKey";
NSString * const ZJPickerViewPropertyIsShowTipLabelKey = @"ZJPickerViewPropertyIsShowTipLabelKey";
NSString * const ZJPickerViewPropertyIsShowSelectContentKey = @"ZJPickerViewPropertyIsShowSelectContentKey";
NSString * const ZJPickerViewPropertyIsScrollToSelectedRowKey = @"ZJPickerViewPropertyIsScrollToSelectedRowKey";
NSString * const ZJPickerViewPropertyIsDividedSelectContentKey = @"ZJPickerViewPropertyIsDividedSelectContentKey";
NSString * const ZJPickerViewPropertyIsAnimationShowKey = @"ZJPickerViewPropertyIsAnimationShowKey";
// CGFloat type
NSString * const ZJPickerViewPropertyBackgroundAlphaKey = @"ZJPickerViewPropertyBackgroundAlphaKey";
 
//2019-09-05
NSString * const ZJPickerViewPropertyDefaultSelectedIndexKey = @"ZJPickerViewPropertyDefaultSelectedIndexKey";
 
 
static const CGFloat toolViewHeight = 44.0f; // tool view height
static const CGFloat canceBtnWidth = 68.0f; // cance button or sure button height
static NSString * const kDividedSymbol = @","; // divided symbol
 
@interface ZJPickerView ()<UIPickerViewDataSource, UIPickerViewDelegate>
 
// property
@property (nonatomic, strong) NSMutableArray *dataList; // data list
@property (nonatomic, strong) NSMutableArray *mSecondDataList; // 二级 list
@property (nonatomic, strong) NSMutableArray *mThirdDataList; // 三级 list
 
 
@property (nonatomic, strong) NSMutableDictionary *propertyDict; // property dictionary
 
// pickerView
@property (nonatomic, assign) NSUInteger component; // component numbers, default 0
@property (nonatomic, assign) CGFloat pickerViewHeight; // pickerView height, default 224 pt
@property (nonatomic, assign) CGFloat oneComponentRowHeight; // one component row height, default 32 pt
@property (nonatomic, strong) NSDictionary *selectRowTitleAttribute; // select row titlt attribute
@property (nonatomic, strong) NSDictionary *unSelectRowTitleAttribute; // unSelect row titlt attribute
@property (nonatomic, strong) UIColor *selectRowLineBackgroundColor; // select row top and bottom line backgroundColor
@property (nonatomic, copy) NSString *dividedSymbol; // divided symbol, default commas
 
@property (nonatomic, assign) BOOL isTouchBackgroundHide; // touch background is hide, default NO
@property (nonatomic, assign) BOOL isShowTipLabel; // is show tipLabel, default NO.
@property (nonatomic, assign) BOOL isShowSelectContent; // scroll component is update and show select content in tipLabel, default NO
@property (nonatomic, assign) BOOL isScrollToSelectedRow; // pickerView will show scroll to selected row, default NO
@property (nonatomic, assign) BOOL isDividedSelectContent; // select content is divided, default NO
@property (nonatomic, assign) BOOL isAnimationShow; // show pickerView is need Animation, default YES
@property (nonatomic, assign) BOOL isSettedSelectRowLineBackgroundColor; // is setted select row top and bottom line backgroundColor, default NO
@property (nonatomic, assign) CGFloat backgroundAlpha; // background alpha, default 0.5(0.0~1.0)
//@property (nonatomic, copy) void(^completion)(NSString * _Nullable  selectContent); // select content
@property (nonatomic, copy) void(^completion)(NSInteger, NSInteger, NSInteger); //2019-09-05  select content
 
// subviews
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, strong) UIButton *canceBtn;
@property (nonatomic, strong) UIButton *sureBtn;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) UIView *lineView;
 
//2019-9-5 新增默认选择项,和回调选中的索引
@property (nonatomic, assign) NSInteger selectIndex1;
@property (nonatomic, assign) NSInteger selectIndex2;
@property (nonatomic, assign) NSInteger selectIndex3;
@property (nonatomic, strong) UIColor *btnColor;
 
@property (nonatomic, assign) BOOL isLinked; //是否不联动
 
@end
 
@implementation ZJPickerView
 
+ (ZJPickerView *)sharedView {
    static dispatch_once_t once;
    static ZJPickerView *sharedView;
    dispatch_once(&once, ^{ sharedView = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; });
    return sharedView;
}
 
#pragma mark - Instance Methods
- (instancetype)initWithFrame:(CGRect)frame {
    if((self = [super initWithFrame:frame])) {
        [self initDefaultConfig];
        self.dataList = [NSMutableArray array];
        self.mSecondDataList = [NSMutableArray array];
        self.mThirdDataList = [NSMutableArray array];
        self.propertyDict = [NSMutableDictionary dictionary];
        [self initSubViews];
    }
    return self;
}
 
- (void)initDefaultConfig
{
    
    self.isLinked = YES;
    self.selectIndex1 = 0;
    self.selectIndex2 = 0;
    self.selectIndex3 = 0;
    self.component = 0;
    self.pickerViewHeight = 224.0f;
    self.oneComponentRowHeight = 32.0f;
    self.selectRowTitleAttribute = @{NSForegroundColorAttributeName : [UIColor blackColor], NSFontAttributeName : [UIFont systemFontOfSize:20.0f]};
    self.unSelectRowTitleAttribute = @{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName : [UIFont systemFontOfSize:20.0f]};
    self.selectRowLineBackgroundColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0 blue:222.0/255.0 alpha:1.0];
    self.btnColor = [UIColor colorWithRed:255.0/255.0 green:87.0/255.0 blue:34.0/255.0 alpha:1.0];
    self.dividedSymbol = kDividedSymbol;
    
    self.isTouchBackgroundHide = NO;
    self.isShowTipLabel = NO;
    self.isShowSelectContent = NO;
    self.isScrollToSelectedRow = NO;
    self.isDividedSelectContent = NO;
    self.isAnimationShow = YES;
    self.isSettedSelectRowLineBackgroundColor = NO;
    self.backgroundAlpha = 0.5f;
}
 
-(void)setRadiusWithView:(UIView *)mView{
    //顶部圆角
    UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
    if (@available(iOS 11.0, *)) {
        mView.layer.cornerRadius = 20;
        mView.layer.maskedCorners =  (CACornerMask)corners; // 左上圆角
    }else{
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:mView.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(20,20)];
        //创建 layer
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = mView.bounds;
        //赋值
        maskLayer.path = maskPath.CGPath;
        mView.layer.mask = maskLayer;
    }
}
 
 
- (void)initSubViews
{
    // background view
    UIView *backgroundView = [[UIView alloc] initWithFrame:self.bounds];
    backgroundView.backgroundColor = [UIColor blackColor];
    backgroundView.alpha = self.backgroundAlpha;
    [self addSubview:backgroundView];
    
    // add tap Gesture
    UITapGestureRecognizer *tapbgGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchBackgroundView)];
    [backgroundView addGestureRecognizer:tapbgGesture];
    
    // content view
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - toolViewHeight - self.pickerViewHeight, self.frame.size.width, toolViewHeight + self.pickerViewHeight)];
    contentView.backgroundColor = [UIColor whiteColor];
    [self setRadiusWithView:contentView];
    [self addSubview:contentView];
    
    // tool view
    UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, toolViewHeight)];
    toolView.backgroundColor = [UIColor whiteColor];
    [self setRadiusWithView:toolView];
    [contentView addSubview:toolView];
    
    //    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 1)];
    //    lineView.backgroundColor = [UIColor lightGrayColor];
    //    [contentView addSubview:lineView];
    //
    // cance button
    NSArray *diffLanguageTitles = [self getDiffLanguageCanceAndSureBtnTitles];
    UIButton *canceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    canceBtn.frame = CGRectMake(0, 0, canceBtnWidth, toolView.frame.size.height);
    [canceBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [canceBtn setTitle:diffLanguageTitles.firstObject forState:UIControlStateNormal];
    //    [canceBtn.titleLabel setFont:[UIFont systemFontOfSize:17.0]];
    canceBtn.titleLabel.font = [UIFont fontWithName:APP_UIFont size:14];
    [canceBtn setTag:0];
    [canceBtn addTarget:self action:@selector(userAction:) forControlEvents:UIControlEventTouchUpInside];
    [toolView addSubview:canceBtn];
    
    // sure button
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(toolView.frame.size.width - canceBtnWidth, 0, canceBtnWidth, toolView.frame.size.height);
    [sureBtn setTitleColor:self.btnColor forState:UIControlStateNormal];
    [sureBtn setTitle:diffLanguageTitles.lastObject forState:UIControlStateNormal];
    //    [sureBtn.titleLabel setFont:[UIFont systemFontOfSize:17.0]];
    sureBtn.titleLabel.font = [UIFont fontWithName:APP_UIFont size:14];
    [sureBtn setTag:1];
    [sureBtn addTarget:self action:@selector(userAction:) forControlEvents:UIControlEventTouchUpInside];
    [toolView addSubview:sureBtn];
    
    // center title
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(canceBtn.frame.size.width, 0, toolView.frame.size.width - canceBtn.frame.size.width*2, toolView.frame.size.height)];
    tipLabel.text = @"";
    tipLabel.textColor = [UIColor darkTextColor];
    //    tipLabel.font = [UIFont systemFontOfSize:17.0];
    tipLabel.font = [UIFont fontWithName:APP_UIFont size:16];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.hidden = !self.isShowTipLabel;
    [toolView addSubview:tipLabel];
    
    // line view
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, toolView.frame.size.height - 0.5f, self.frame.size.width, 0.5f)];
    lineView.backgroundColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0 blue:222.0/255.0 alpha:1.0];
    [toolView addSubview:lineView];
    
    // pickerView
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, toolView.frame.size.height, self.frame.size.width, self.pickerViewHeight)];
    pickerView.dataSource = self;
    pickerView.delegate = self;
    [contentView addSubview:pickerView];
    
    // global variable
    self.backgroundView = backgroundView;
    self.contentView = contentView;
    self.canceBtn = canceBtn;
    self.sureBtn = sureBtn;
    self.lineView = lineView;
    self.tipLabel = tipLabel;
    self.pickerView = pickerView;
}
 
#pragma mark - UIPickerView DataSource & Delegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    //    if(self.isLinked){
    //        return self.component;
    //    }else{
    //        return 2;
    //    }
    return self.component;
}
 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(self.isLinked){
        return [self getDataWithComponent:component].count;
    }else{
        return [self getDataWithComponentNoLinked:component].count;
    }
}
 
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSArray *componentArray;
    if(self.isLinked){
        componentArray = [self getDataWithComponent:component];
    }else{
        componentArray = [self getDataWithComponentNoLinked:component];
    }
    
    if (componentArray.count) {
        if (row < componentArray.count) {
            id titleData = componentArray[row];
            if ([titleData isKindOfClass:[NSString class]]) {
                return titleData;
            } else if ([titleData isKindOfClass:[NSNumber class]]) {
                return [NSString stringWithFormat:@"%@", titleData];
            }
        }
    }
    return @"";
}
 
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(self.isLinked){
        if(component == 0){
            self.selectIndex1 = row;
            self.selectIndex2 = 0;
        }else if(component == 1){
            self.selectIndex2 = row;
            self.selectIndex3 = 0;
        }else if(component == 2){
            self.selectIndex3 = row;
        }
        NSLog(@"component:%ld  row: %ld",(long)component,(long)row);
        [pickerView reloadAllComponents];
        for (NSUInteger i = 0; i < self.component; i++) {
            if (i > component) {
                [pickerView selectRow:0 inComponent:i animated:YES];
            }
        }
    }else{
        //        [pickerView selectRow:row inComponent:component animated:YES];
        if(component == 0){
            self.selectIndex1 = row;
            
        }else if(component == 1){
            self.selectIndex2 = row;
        }else if(component == 2){
            self.selectIndex3 = row;
        }
    }
    
    
    //    // show select content
    //    NSMutableString *selectString = [[NSMutableString alloc] init];
    
    // reload all component and scroll to top for sub component
    //    [pickerView reloadAllComponents];
    //    for (NSUInteger i = 0; i < self.component; i++) {
    //        if (i > component) {
    //            [pickerView selectRow:0 inComponent:i animated:YES];
    //        }
    //
    //        if (self.isShowSelectContent) {
    //            [selectString appendString:[self pickerView:pickerView titleForRow:[pickerView selectedRowInComponent:i] forComponent:i]];
    //            if (i == self.component - 1) {
    //                self.tipLabel.text = selectString;
    //            }
    //        }
    //    }
}
 
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return self.oneComponentRowHeight;
}
 
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    // set separateline color
    if (NO == self.isSettedSelectRowLineBackgroundColor) {
        UIView *topSeparateLine = [pickerView.subviews objectAtIndex:1];
        UIView *bottomSeparateLine = [pickerView.subviews objectAtIndex:2];
        if (topSeparateLine.frame.size.height < 1.0f &&
            bottomSeparateLine.frame.size.height < 1.0f) {
            topSeparateLine.backgroundColor = self.selectRowLineBackgroundColor;
            bottomSeparateLine.backgroundColor = self.selectRowLineBackgroundColor;
            self.isSettedSelectRowLineBackgroundColor = YES;
        } else {
            for (UIView *singleLine in pickerView.subviews) {
                if (singleLine.frame.size.height < 1.0f) {
                    singleLine.backgroundColor = self.selectRowLineBackgroundColor;
                    self.isSettedSelectRowLineBackgroundColor = YES;
                }
            }
        }
    }
    
    // custom pickerView content label
    UILabel *pickerLabel = (UILabel *)view;
    
    // discussion: this is always nil, not Reusing, it's an iOS System bug.
    // reference: https://stackoverflow.com/questions/20635949/reusing-view-in-uipickerview-with-ios-7/21039321#21039321
    if (!pickerLabel) {
        pickerLabel = [[UILabel alloc] init];
        pickerLabel.textAlignment = NSTextAlignmentCenter;
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        pickerLabel.backgroundColor = [UIColor clearColor];
    }
    pickerLabel.attributedText = [self pickerView:pickerView attributedTitleForRow:row forComponent:component];
    
    return pickerLabel;
}
//
- (nullable NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    //    NSString *normalRowString = [self pickerView:pickerView titleForRow:row forComponent:component];
    //    NSString *selectRowString = [self pickerView:pickerView titleForRow:[pickerView selectedRowInComponent:component] forComponent:component];
    //
    //    NSLog(@"selectedRowInComponent ROW :%ld  selectRowString:%@", [pickerView selectedRowInComponent:component],selectRowString);
    //    if (row == [pickerView selectedRowInComponent:component]) {
    //        return [[NSAttributedString alloc] initWithString:selectRowString attributes:self.selectRowTitleAttribute];
    //    } else {
    //        return [[NSAttributedString alloc] initWithString:normalRowString attributes:self.unSelectRowTitleAttribute];
    //    }
    //
    NSString *normalRowString = [self pickerView:pickerView titleForRow:row forComponent:component];
    return [[NSAttributedString alloc] initWithString:normalRowString attributes:self.selectRowTitleAttribute];
}
 
#pragma mark click cance/sure button
- (void)userAction:(UIButton *)sender
{
    // hide
    [self zj_hide];
    // click sure
    if (sender.tag == 1) {
        // completion callback
        if (self.completion) {
            self.completion(self.selectIndex1, self.selectIndex2, self.selectIndex3);
        }
    }
}
 
#pragma mark touch backgroundView
- (void)touchBackgroundView
{
    if (self.isTouchBackgroundHide) {
        [self zj_hide];
    }
}
 
#pragma mark - show & hide method
+ (void)zj_showWithDataList:(nonnull NSArray *)dataList
               propertyDict:(nullable NSDictionary *)propertyDict
                 completion:(nullable void(^)(NSInteger, NSInteger, NSInteger))completion
{
    // no data
    if (!dataList || dataList.count == 0) {
        return;
    }
    
    
    NSDictionary *propertyDict1 = @{
        //                                    ZJPickerViewPropertyCanceBtnTitleKey : @"",
        ZJPickerViewPropertyIsTouchBackgroundHideKey : @YES,
        ZJPickerViewPropertyIsShowSelectContentKey : @YES,
        ZJPickerViewPropertyIsScrollToSelectedRowKey: @YES,
        ZJPickerViewPropertyIsAnimationShowKey : @YES,
        
    };
    
    // handle data
    [[self sharedView] initDefaultConfig];
    [self sharedView].tipLabel.text = @"";
    [[self sharedView].dataList removeAllObjects];
    [[self sharedView].dataList addObjectsFromArray:dataList];
    [[self sharedView].propertyDict removeAllObjects];
    [[self sharedView].propertyDict addEntriesFromDictionary:propertyDict];
    [[self sharedView].propertyDict addEntriesFromDictionary:propertyDict1];
    [[self sharedView] updateCustomProperiesSetter];
    
    // calculate component num
    id data = dataList.firstObject;
    if ([data isKindOfClass:[NSString class]] ||
        [data isKindOfClass:[NSNumber class]] ) {
        [self sharedView].component = 1;
    } else if ([data isKindOfClass:[NSDictionary class]]) {
        [self sharedView].component++;
        [self handleDictDataList:dataList];
    } else {
        NSLog(@"ZJPickerView error tip:\"Unsupported data type\"");
        return;
    }
    
    // discussion: reload component in main queue, fix the first scroll to select line error bug.
    // scorll all component to selectedRow/top
    dispatch_async(dispatch_get_main_queue(), ^{
        [[self sharedView].pickerView reloadAllComponents];
        if ([self sharedView].isScrollToSelectedRow) {
            [[self sharedView] scrollToSelectedRow];
        } else {
            for (NSUInteger i = 0; i < [self sharedView].component; i++) {
                [[self sharedView].pickerView selectRow:0 inComponent:i animated:NO];
            }
        }
    });
    
    // complete block
    if (completion) {
        [self sharedView].completion = completion;
    }
    
    // show
    if ([self sharedView].isAnimationShow) {
        [[[[UIApplication sharedApplication] delegate] window] addSubview:[self sharedView]];
        
        [self sharedView].backgroundView.alpha = 0.0f;
        
        CGRect frame = [self sharedView].contentView.frame;
        frame.origin.y = [self sharedView].frame.size.height;
        [self sharedView].contentView.frame = frame;
        
        __weak typeof(self) weakself = self;
        [UIView animateWithDuration:0.3f animations:^{
            CGRect frame = [weakself sharedView].contentView.frame;
            frame.origin.y = [weakself sharedView].frame.size.height - [weakself sharedView].contentView.frame.size.height;
            [weakself sharedView].contentView.frame = frame;
            [weakself sharedView].backgroundView.alpha = [weakself sharedView].backgroundAlpha;
        }];
    } else {
        [UIView animateWithDuration:0.3f animations:^{
            [[[[UIApplication sharedApplication] delegate] window] addSubview:[self sharedView]];
        }];
    }
}
 
- (void)zj_hide
{
    __weak typeof(self) weakself = self;
    if (self.isAnimationShow) {
        CGRect frame = self.contentView.frame;
        frame.origin.y = self.frame.size.height;
        [UIView animateWithDuration:0.3f animations:^{
            weakself.contentView.frame = frame;
            weakself.backgroundView.alpha = 0.0f;
        } completion:^(BOOL finished) {
            [weakself removeFromSuperview];
        }];
    } else {
        [UIView animateWithDuration:0.3f animations:^{
            [weakself removeFromSuperview];
        }];
    }
}
 
#pragma mark - private method
+ (void)handleDictDataList:(NSArray *)list
{
    id data = list.firstObject;
    if ([data isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dict = data;
        id value = dict.allValues.firstObject;
        if ([value isKindOfClass:[NSArray class]]) {
            [self sharedView].component++;
            [self handleDictDataList:value];
        }
    }
}
 
- (NSArray *)getDataWithComponent:(NSInteger)component
{
    NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.dataList];
    NSMutableArray *arrayM = [NSMutableArray array];
    for (NSInteger i = 0; i <= component; i++) {
        if (i == component) {
            id data = tempArray.firstObject;
            if ([data isKindOfClass:[NSDictionary class]]) {
                NSMutableArray *tempTitleArray = [NSMutableArray arrayWithArray:tempArray];
                [tempArray removeAllObjects];
                [tempTitleArray enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL * _Nonnull stop) {
                    [tempArray addObjectsFromArray:dict.allKeys];
                }];
                [arrayM addObjectsFromArray:tempArray];
            } else if ([data isKindOfClass:[NSString class]] ||
                       [data isKindOfClass:[NSNumber class]]){
                [arrayM addObjectsFromArray:tempArray];
            }
        } else {
            NSInteger selectRow = [self.pickerView selectedRowInComponent:i];
            if (selectRow < tempArray.count) {
                id data = tempArray[selectRow];
                if ([data isKindOfClass:[NSDictionary class]]) {
                    [tempArray removeAllObjects];
                    NSDictionary *dict = data;
                    [dict.allValues enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        if ([obj isKindOfClass:[NSArray class]]) {
                            [tempArray addObjectsFromArray:obj];
                        } else {
                            [tempArray addObject:obj];
                        }
                    }];
                }
            }
        }
    }
    return arrayM;
}
 
- (NSArray *)getDataWithComponentNoLinked:(NSInteger)component
{
    //    NSMutableArray *arrayM = [NSMutableArray array];
    if(component == 0){
        return self.dataList;
    }else if(component == 1){
        return self.mSecondDataList;
    }else if(component == 2){
        return self.mThirdDataList;
    }else{
        NSMutableArray *arrayM = [NSMutableArray array];
        return arrayM;
    }
}
 
 
 
#pragma mark update property
- (void)updateCustomProperiesSetter
{
    [self.propertyDict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        if (obj) {
            if ([key isEqualToString:ZJPickerViewPropertyCanceBtnTitleKey]) {
                [self.canceBtn setTitle:obj forState:UIControlStateNormal];
            } else if ([key isEqualToString:ZJPickerViewPropertySureBtnTitleKey]) {
                [self.sureBtn setTitle:obj forState:UIControlStateNormal];
            } else if ([key isEqualToString:ZJPickerViewPropertyTipLabelTextKey]) {
                self.tipLabel.text = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertyDividedSymbolKey]) {
                self.dividedSymbol = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertyCanceBtnTitleColorKey]) {
                [self.canceBtn setTitleColor:obj forState:UIControlStateNormal];
            } else if ([key isEqualToString:ZJPickerViewPropertySureBtnTitleColorKey]) {
                [self.sureBtn setTitleColor:obj forState:UIControlStateNormal];
            } else if ([key isEqualToString:ZJPickerViewPropertyTipLabelTextColorKey]) {
                self.tipLabel.textColor = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertyLineViewBackgroundColorKey]) {
                self.lineView.backgroundColor = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertyCanceBtnTitleFontKey]) {
                [self.canceBtn.titleLabel setFont:obj];
            } else if ([key isEqualToString:ZJPickerViewPropertySureBtnTitleFontKey]) {
                [self.sureBtn.titleLabel setFont:obj];
            } else if ([key isEqualToString:ZJPickerViewPropertyTipLabelTextFontKey]) {
                [self.tipLabel setFont:obj];
            } else if ([key isEqualToString:ZJPickerViewPropertyPickerViewHeightKey]) {
                self.pickerViewHeight = [obj floatValue];
                CGRect frame = self.pickerView.frame;
                frame.size.height = self.pickerViewHeight;
                self.pickerView.frame = frame;
                
                frame = self.contentView.frame;
                frame.size.height = toolViewHeight + self.pickerViewHeight;
                frame.origin.y = self.frame.size.height - frame.size.height;
                self.contentView.frame = frame;
            } else if ([key isEqualToString:ZJPickerViewPropertyOneComponentRowHeightKey]) {
                self.oneComponentRowHeight = [obj floatValue];
            } else if ([key isEqualToString:ZJPickerViewPropertySelectRowTitleAttrKey]) {
                self.selectRowTitleAttribute = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertyUnSelectRowTitleAttrKey]) {
                self.unSelectRowTitleAttribute = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertySelectRowLineBackgroundColorKey]) {
                self.selectRowLineBackgroundColor = obj;
            } else if ([key isEqualToString:ZJPickerViewPropertyIsTouchBackgroundHideKey]) {
                self.isTouchBackgroundHide = [obj boolValue];
            } else if ([key isEqualToString:ZJPickerViewPropertyIsShowTipLabelKey]) {
                self.isShowTipLabel = [obj boolValue]; // NO
                self.tipLabel.hidden = self.isShowSelectContent ? NO : !self.isShowTipLabel;
            } else if ([key isEqualToString:ZJPickerViewPropertyIsShowSelectContentKey]) {
                self.isShowSelectContent = [obj boolValue]; // NO
                if (self.isShowSelectContent) {
                    self.tipLabel.hidden = NO;
                }
            } else if ([key isEqualToString:ZJPickerViewPropertyIsScrollToSelectedRowKey]) {
                self.isScrollToSelectedRow = [obj boolValue];
            } else if ([key isEqualToString:ZJPickerViewPropertyIsDividedSelectContentKey]) {
                self.isDividedSelectContent = [obj boolValue];
            } else if ([key isEqualToString:ZJPickerViewPropertyBackgroundAlphaKey]) {
                self.backgroundAlpha = [obj floatValue];
                self.backgroundView.alpha = self.backgroundAlpha;
            } else if ([key isEqualToString:ZJPickerViewPropertyIsAnimationShowKey]) {
                self.isAnimationShow = [obj boolValue];
            } else if ([key isEqualToString:ZJPickerViewPropertyDefaultSelectedIndexKey]) {
                
                NSArray *array = [obj componentsSeparatedByString:@"-"]; //分割数组
                if(array.count == 1){
                    self.selectIndex1 = [array[0] intValue];
                }else if(array.count == 2){
                    self.selectIndex1 = [array[0] intValue];
                    self.selectIndex2 = [array[1] intValue];
                }else if(array.count == 3){
                    self.selectIndex1 = [array[0] intValue];
                    self.selectIndex2 = [array[1] intValue];
                    self.selectIndex3 = [array[2] intValue];
                }
            }
        }
    }];
}
 
/*
 * 2019-09-05 根据索引选中,替换原来根据传入字符选中方案
 */
- (void)scrollToSelectedRow
{
    for (NSUInteger i = 0; i < self.component; i++) {
        if(i == 0){
            [self.pickerView selectRow:self.selectIndex1 inComponent:i animated:NO];
        }else if(i == 1){
            [self.pickerView selectRow:self.selectIndex2 inComponent:i animated:NO];
        }else if(i == 2){
            [self.pickerView selectRow:self.selectIndex3 inComponent:i animated:NO];
        }
        
    }
}
 
//- (void)scrollToSelectedRow
//{
//
//
//    for (NSUInteger i = 0; i < self.component; i++) {
//        if(i == 0){
//            [self.pickerView selectRow:self.selectIndex1 inComponent:i animated:NO];
//        }else if(i == 1){
//            [self.pickerView selectRow:self.selectIndex2 inComponent:i animated:NO];
//        }else if(i == 2){
//            [self.pickerView selectRow:self.selectIndex3 inComponent:i animated:NO];
//        }
//
//    }
//
//    NSString *selectedContent = self.propertyDict[ZJPickerViewPropertyTipLabelTextKey];
//    NSMutableArray *selectContentList = [NSMutableArray arrayWithCapacity:self.component];
//    if (self.isDividedSelectContent) {
//        // reference: https://github.com/Abnerzj/ZJPickerView/issues/8
//        NSArray *tempSelectContentList = [selectedContent componentsSeparatedByString:self.dividedSymbol];
//        if (tempSelectContentList && tempSelectContentList.count == self.component) {
//            [selectContentList addObjectsFromArray:tempSelectContentList];
//        }
//    }
//    if (selectedContent.length && ![selectedContent isEqualToString:@""]) {
//        __weak typeof(self) weakself = self;
//        NSMutableArray *tempSelectedRowArray = [NSMutableArray arrayWithCapacity:self.component];
//        for (NSUInteger i = 0; i < self.component; i++) {
//            NSArray *componentArray = [self getDataWithComponent:i];
//            if (componentArray.count) {
//                [componentArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * _Nonnull stop) {
//                    NSString *title = @"";
//                    if ([obj isKindOfClass:[NSString class]]) {
//                        title = obj;
//                    } else if ([obj isKindOfClass:[NSNumber class]]) {
//                        title = [obj stringValue];
//                    }
//                    if (![title isEqualToString:@""]) {
//                        BOOL isCanScrollToSelectePosition = NO;
//                        if (selectContentList.count > 0) {
//                            isCanScrollToSelectePosition = [selectContentList[i] isEqualToString:title];
//                        } else {
//                            // discussion: scroll to select row error when solving content similar, only appear when there is only one component.
//                            // reference: https://github.com/Abnerzj/ZJPickerView/issues/4
//                            //            https://github.com/Abnerzj/ZJPickerView/issues/5
//                            NSRange range = [selectedContent rangeOfString:title];
//                            isCanScrollToSelectePosition = (self.component == 1) ? ([selectedContent isEqualToString:title]) : (range.location != NSNotFound);
//                        }
//
//                        if (isCanScrollToSelectePosition) {
//                            [tempSelectedRowArray addObject:@(idx)];
//                            [weakself.pickerView reloadComponent:i];
//                            [weakself.pickerView selectRow:idx inComponent:i animated:NO];
//                            [weakself.pickerView reloadComponent:i];
//                            *stop = YES;
//                        }
//                    }
//                }];
//            }
//        }
//
//        if (tempSelectedRowArray.count != self.component) {
//            for (NSUInteger i = 0; i < self.component; i++) {
//                [self.pickerView selectRow:0 inComponent:i animated:NO];
//            }
//        }
//    }
//}
 
- (NSArray *)getDiffLanguageCanceAndSureBtnTitles
{
    NSString *languageName = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
    
    // 简体中文
    if ([languageName rangeOfString:@"zh-Hans"].location != NSNotFound) {
        return @[@"取消", @"确定"];
    }
    
    // 繁体中文
    if ([languageName rangeOfString:@"zh-Hant"].location != NSNotFound) {
        return @[@"取消", @"確定"];
    }
    
    // Other language
    return @[@"Cance", @"Sure"];
}
 
 
/*
 *2019-09-12 新增支持不联动效果
 */
+ (void)zj_showWithDataListWithNotLinked:(nonnull NSArray *)dataList
                             mSecondList:(nonnull NSArray *)mSecondList
                              mThirdList:(nullable NSArray *)mThirdList
                            propertyDict:(nullable NSDictionary *)propertyDict
                              completion:(nullable void(^)(NSInteger, NSInteger, NSInteger))completion
{
    // no data
    if (!dataList || dataList.count == 0) {
        return;
    }
    
    // no data
    if (!mSecondList || mSecondList.count == 0) {
        return;
    }
    
    
    
    NSDictionary *propertyDict1 = @{
        //                                    ZJPickerViewPropertyCanceBtnTitleKey : @"",
        ZJPickerViewPropertyIsTouchBackgroundHideKey : @YES,
        ZJPickerViewPropertyIsShowSelectContentKey : @YES,
        ZJPickerViewPropertyIsScrollToSelectedRowKey: @YES,
        ZJPickerViewPropertyIsAnimationShowKey : @YES,
        
    };
    
    // handle data
    [[self sharedView] initDefaultConfig];
    [self sharedView].tipLabel.text = @"";
    [[self sharedView].dataList removeAllObjects];
    [[self sharedView].mSecondDataList removeAllObjects];
    [[self sharedView].mThirdDataList removeAllObjects];
    [[self sharedView].dataList addObjectsFromArray:dataList];
    [[self sharedView].mSecondDataList addObjectsFromArray:mSecondList];
    [[self sharedView].mThirdDataList addObjectsFromArray:mThirdList];
    [[self sharedView].propertyDict removeAllObjects];
    [[self sharedView].propertyDict addEntriesFromDictionary:propertyDict];
    [[self sharedView].propertyDict addEntriesFromDictionary:propertyDict1];
    [[self sharedView] updateCustomProperiesSetter];
    
    
    //配置关键数据
    if (!mThirdList || mThirdList.count == 0) {
        [self sharedView].component = 2;
    }else{
        [self sharedView].component = 3;
    }
    
    [self sharedView].isLinked = NO;
    
    
    // discussion: reload component in main queue, fix the first scroll to select line error bug.
    // scorll all component to selectedRow/top
    dispatch_async(dispatch_get_main_queue(), ^{
        [[self sharedView].pickerView reloadAllComponents];
        if ([self sharedView].isScrollToSelectedRow) {
            [[self sharedView] scrollToSelectedRow];
        } else {
            for (NSUInteger i = 0; i < [self sharedView].component; i++) {
                [[self sharedView].pickerView selectRow:0 inComponent:i animated:NO];
            }
        }
    });
    
    // complete block
    if (completion) {
        [self sharedView].completion = completion;
    }
    
    // show
    if ([self sharedView].isAnimationShow) {
        [[[[UIApplication sharedApplication] delegate] window] addSubview:[self sharedView]];
        
        [self sharedView].backgroundView.alpha = 0.0f;
        
        CGRect frame = [self sharedView].contentView.frame;
        frame.origin.y = [self sharedView].frame.size.height;
        [self sharedView].contentView.frame = frame;
        
        __weak typeof(self) weakself = self;
        [UIView animateWithDuration:0.3f animations:^{
            CGRect frame = [weakself sharedView].contentView.frame;
            frame.origin.y = [weakself sharedView].frame.size.height - [weakself sharedView].contentView.frame.size.height;
            [weakself sharedView].contentView.frame = frame;
            [weakself sharedView].backgroundView.alpha = [weakself sharedView].backgroundAlpha;
        }];
    } else {
        [UIView animateWithDuration:0.3f animations:^{
            [[[[UIApplication sharedApplication] delegate] window] addSubview:[self sharedView]];
        }];
    }
}
 
 
 
@end