123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // YOUPAISelectOccupationVC.m
- // MSYOUPAI
- //
- // Created by admin on 2022/3/9.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAISelectOccupationVC.h"
- @interface YOUPAISelectOccupationVC ()
- @end
- @implementation YOUPAISelectOccupationVC
- -(UIView *)customView{
- if(_customView == nil){
- _customView = [UIView new];
- _customView.backgroundColor = UIColor.whiteColor;
- }
- return _customView;
- }
- -(YOUPAIPickerViewHeader *)youpaipHeader{
- if(_youpaipHeader == nil){
- _youpaipHeader = [YOUPAIPickerViewHeader new];
- _youpaipHeader.backgroundColor = UIColor.whiteColor;
- [_youpaipHeader.youpaipCommitBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [_youpaipHeader.youpaipCancleBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _youpaipHeader;
- }
- -(PGPickerView *)pickerView{
-
- if( _pickerView == nil){
- _pickerView = [PGPickerView new];
- _pickerView.type = PGPickerViewLineTypeline;
- _pickerView.lineBackgroundColor = [UIColor clearColor];
- _pickerView.lineHeight = 0.0f;
- _pickerView.verticalLineBackgroundColor = [UIColor clearColor];
- _pickerView.verticalLineWidth = 0.0f;
- _pickerView.backgroundColor = [UIColor whiteColor];
- _pickerView.isHiddenMiddleText = YES;
- _pickerView.middleTextColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2f];
- _pickerView.textColorOfSelectedRow = LZ273145Color;
- _pickerView.textColorOfOtherRow = LZD3D1D7Color;
- _pickerView.textFontOfSelectedRow = LCFont(17);
- _pickerView.textFontOfOtherRow = LCFont(17);
- _pickerView.lineBackgroundColor = [UIColor clearColor];
- _pickerView.delegate = self;
- _pickerView.dataSource = self;
- }
- return _pickerView;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.baseView setHidden:true];
- self.isTouchDismiss = true;
- [self youpaifInitValue];
- [self youpaifMakeUI];
- [self youpaifMakeLayout];
-
- }
- -(void)youpaifInitValue{
- }
- -(void)setSelectIndex:(NSIndexPath*)selectIndex{
-
- if (_selectIndex == selectIndex){
- return;
- }
- _selectIndex = selectIndex;
- [self.pickerView reloadAllComponents];
-
- }
- - (void)youpaifMakeUI{
-
-
- [self.view addSubview:self.customView];
- [self.customView addSubview:self.youpaipHeader];
- [self.customView addSubview:self.pickerView];
- }
- -(void)youpaifMakeLayout{
- [_pickerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(-(SafeHeight+8));
- make.left.mas_equalTo(8);
- make.right.mas_equalTo(-8);
- make.height.mas_equalTo(180);
- }];
- [_youpaipHeader mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(49);
- }];
- [_customView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.bottom.mas_equalTo(0);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(209+SafeHeight+49);
- }];
- [self.view layoutIfNeeded];
- [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:_customView size:CGSizeMake(16, 16)];
- }
- - (void)cancelBtnClick{
- [self dismissViewControllerAnimated:true completion:nil];
- }
- - (void)confirmBtnClick{
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOccupation:occupation:)]) {
- NSDictionary *dic = [self.dataSouce objectAtIndex:_selectIndex.section];
- NSArray *rowdata = dic[@"val"];
- [self.delegate didSelectOccupation:self occupation:rowdata[_selectIndex.row]];
-
- }
- [self dismissViewControllerAnimated:true completion:nil];
- }
- - (NSInteger)numberOfComponentsInPickerView:(PGPickerView *)pickerView{
- return 2;
- }
- - (NSInteger)pickerView:(PGPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
- if (component == 0){
- return self.dataSouce.count;
- }else{
- NSDictionary *dic = [self.dataSouce objectAtIndex:self.selectIndex.section];
- NSArray *datas = dic[@"val"];
- return datas.count;
- }
-
- }
- - (NSString *)pickerView:(PGPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
-
- if (component == 0){
- NSDictionary *dic = [self.dataSouce objectAtIndex:row];
- return dic[@"key"];
- }else{
- NSDictionary *dic = [self.dataSouce objectAtIndex:_selectIndex.section];
- NSArray *rowdata = dic[@"val"];
- if (row< [rowdata count]){
- return rowdata[row];
- }else{
- return @"";
- }
-
- }
- }
- - (void)pickerView:(PGPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
- if(component==0){
-
- NSInteger select = MIN(row,_dataSouce.count-1);
- self.selectIndex = [NSIndexPath indexPathForRow:0 inSection:select];
- }else{
- NSDictionary *dic = [self.dataSouce objectAtIndex:_selectIndex.section];
- NSArray *rowdata = dic[@"val"];
- NSInteger select = MIN(row,rowdata.count-1);
- self.selectIndex = [NSIndexPath indexPathForRow:select inSection:_selectIndex.section];
- }
- }
- @end
|