//
|
// PBOneChooseView.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2018/12/19.
|
// Copyright © 2018 ProBIM. All rights reserved.
|
//
|
|
#import "PBOneChooseView.h"
|
#import "PBExamineAddModel.h"
|
@interface PBOneChooseView()<UIPickerViewDelegate,UIPickerViewDataSource>
|
@property (nonatomic, strong) UIView *bgView;
|
@property (nonatomic, strong) UIPickerView *pickerView;
|
@property (nonatomic, weak) UILabel *engineeringTieleL;
|
@property (nonatomic, weak) UILabel *engineeringSelectL;
|
@property (nonatomic, weak) UILabel *promptL;
|
@property (nonatomic, strong) NSDictionary *selectDate;
|
@property (nonatomic, assign) BOOL isSelect;
|
@end
|
@implementation PBOneChooseView
|
- (instancetype)initWithFrame:(CGRect)frame {
|
if (self = [super initWithFrame:frame]) {
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
[self addSubview:self.bgView];
|
[self setupUI];
|
}
|
return self;
|
}
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
CGPoint point = [[touches anyObject]locationInView:self];
|
CALayer *layer = [self.layer hitTest:point];
|
if (layer == self.layer) {
|
[self hidden];
|
}
|
}
|
- (void)hidden {
|
if (self.ChooseCompleteBlock) {
|
self.ChooseCompleteBlock(_isSelect);
|
}
|
[UIView animateWithDuration:0.3 animations:^{
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
self.bgView.y = PBScreenHeight;
|
}completion:^(BOOL finished) {
|
for (UIView *cover in PBKeyWindow.subviews) {
|
if ([cover isKindOfClass:[PBOneChooseView class]]) {
|
[cover removeFromSuperview];
|
}
|
}
|
}];
|
}
|
- (void)show {
|
[UIView animateWithDuration:0.3 animations:^{
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
|
self.bgView.y = PBScreenHeight - self.visualViewHeight;
|
}];
|
}
|
#pragma mark - 懒加载
|
- (UIView *)bgView {
|
if (_bgView == nil) {
|
_bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, PBScreenHeight)];
|
_bgView.backgroundColor = [UIColor whiteColor];
|
}
|
return _bgView;
|
}
|
- (void)setVisualViewHeight:(NSInteger)visualViewHeight {
|
_visualViewHeight = visualViewHeight;
|
}
|
|
- (void)setupUI {
|
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 3)];
|
topView.backgroundColor = WarningColor;
|
[self.bgView addSubview:topView];
|
|
UILabel *engineeringTieleL = [UILabel z_labelWithText:@"状态" Color:PromptColor isBold:NO Font:DescFontSize];
|
[self.bgView addSubview:engineeringTieleL];
|
[engineeringTieleL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(topView.mas_bottom).offset(34);
|
make.centerX.equalTo(self.bgView);
|
make.height.equalTo(@20);
|
}];
|
|
UILabel *engineeringSelectL = [UILabel z_labelWithText:@"请选择" Color:IgnoreColor isBold:NO Font:MarkedFontSize];
|
engineeringSelectL.textAlignment = NSTextAlignmentCenter;
|
[self.bgView addSubview:engineeringSelectL];
|
[engineeringSelectL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(engineeringTieleL.mas_bottom).offset(14);
|
make.left.equalTo(self.bgView).offset(16);
|
make.right.equalTo(self.bgView).offset(-16);
|
make.height.equalTo(@25);
|
}];
|
|
UIView *lin1View = [[UIView alloc] init];
|
lin1View.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242];
|
[self.bgView addSubview:lin1View];
|
[lin1View mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(topView.mas_bottom).offset(132);
|
make.left.right.equalTo(self.bgView);
|
make.height.equalTo(@1);
|
}];
|
|
UILabel *promptL = [UILabel z_labelWithText:@"请选择单位工程" Color:PromptColor isBold:NO Font:MarkedFontSize];
|
promptL.textAlignment = NSTextAlignmentCenter;
|
[self.bgView addSubview:promptL];
|
[promptL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(lin1View).offset(15);
|
make.size.mas_equalTo(CGSizeMake(130, 25));
|
make.centerX.equalTo(self.bgView);
|
}];
|
|
UIButton *determineBtn = [UIButton z_textButton:@"确定" fontSize:MarkedFontSize normalColor:WarningColor];
|
[self.bgView addSubview:determineBtn];
|
[determineBtn addTarget:self action:@selector(determineBtnActio) forControlEvents:UIControlEventTouchUpInside];
|
[determineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(promptL);
|
make.right.equalTo(self.bgView).offset(-16);
|
make.size.mas_equalTo(CGSizeMake(52, 50));
|
}];
|
|
UIView *lin2View = [[UIView alloc] init];
|
lin2View.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242];
|
[self.bgView addSubview:lin2View];
|
[lin2View mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(lin1View.mas_bottom).offset(54);
|
make.left.right.equalTo(self.bgView);
|
make.height.equalTo(@1);
|
}];
|
|
self.pickerView = [[UIPickerView alloc]init];
|
self.pickerView.backgroundColor = [UIColor whiteColor];
|
self.pickerView.delegate = self;
|
self.pickerView.dataSource = self;
|
[self.bgView addSubview:self.pickerView];
|
[self.pickerView reloadAllComponents];//刷新UIPickerView
|
[self.pickerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(lin2View.mas_bottom);
|
make.right.equalTo(self.bgView).offset(-44);
|
make.left.equalTo(self.bgView).offset(44);
|
make.height.equalTo(@282);
|
}];
|
self.engineeringTieleL = engineeringTieleL;
|
self.engineeringSelectL = engineeringSelectL;
|
self.promptL = promptL;
|
}
|
|
//确定按钮点击方法
|
- (void)determineBtnActio {
|
self.isSelect = YES;
|
self.examineAddModel.dataDict = self.selectDate;
|
self.engineeringSelectL.text = [self.examineAddModel.dataDict valueForKey:@"name"];
|
[self hidden];
|
}
|
|
|
#pragma mark UIPickerViewDelegate && UIPickerViewDataSource
|
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
|
return 1;
|
}
|
|
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
|
return self.dataArr.count;
|
}
|
|
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
|
return 60.f;
|
}
|
|
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
|
self.selectDate = self.dataArr[row];
|
}
|
|
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
|
for(UIView *singleLine in pickerView.subviews){
|
if (singleLine.frame.size.height < 1){
|
singleLine.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242];
|
}
|
}
|
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width / 2, 30)];
|
label.textAlignment = NSTextAlignmentCenter;
|
label.font = [UIFont systemFontOfSize:20];
|
NSDictionary *dict = self.dataArr[row];
|
label.text = [dict valueForKey:@"name"];
|
return label;
|
}
|
|
- (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel {
|
_examineAddModel = examineAddModel;
|
self.engineeringTieleL.text = examineAddModel.title;
|
if (examineAddModel.dataDict) {
|
self.engineeringSelectL.text = [examineAddModel.dataDict valueForKey:@"name"];
|
self.engineeringSelectL.textColor = TitleColor;
|
}else {
|
self.engineeringSelectL.text = examineAddModel.prompt;
|
self.engineeringSelectL.textColor = IgnoreColor;
|
}
|
}
|
- (void)setDataArr:(NSArray *)dataArr {
|
_dataArr = dataArr;
|
self.selectDate = dataArr[0];
|
}
|
@end
|