agiapp / BRPickerView

BRPickerView 封装的是iOS中常用的选择器组件,主要包括:日期选择器(支持年月日、年月等15种日期样式选择,支持设置星期、至今等)、地址选择器(支持省市区、省市、省三种地区选择)、自定义字符串选择器(支持单列、多列、二级联动、三级联动选择)。支持自定义主题样式,适配深色模式,支持将选择器组件添加到指定容器视图。
https://github.com/agiapp/BRPickerView
MIT License
2.54k stars 440 forks source link

我帮你加了一个功能 #168

Closed 295060456 closed 3 months ago

295060456 commented 4 years ago

在 BRDatePickerView.m 里面: 1、@property (nonatomic, strong) UILabel messageLabel; 2、- (UIView )pickerView:(UIPickerView )pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView )view 里面 加上 NSDateFormatter formatter = NSDateFormatter.new; [formatter setDateFormat:@"yyyy"]; //只显示年 self.messageLabel.text = [formatter stringFromDate:self.mSelectDate]; 3、在 - (UIPickerView )pickerView 里面加上: _pickerView.alpha = 0.5;

现在就可以背景显示年

agiapp commented 4 years ago

这个功能不需要修改源码额外定制的,参考如下代码:

使用

BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
datePickerView.pickerMode = BRDatePickerModeYMD;
datePickerView.title = @"请选择年月日";
datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
    NSLog(@"selectValue=%@", selectValue);
    NSLog(@"selectDate=%@", selectDate);
};

// 设置年份背景
UILabel *yearLabel = [[UILabel alloc]initWithFrame:datePickerView.alertView.bounds];
yearLabel.backgroundColor = [UIColor clearColor];
yearLabel.textAlignment = NSTextAlignmentCenter;
yearLabel.textColor = [[UIColor grayColor] colorWithAlphaComponent:0.2f];
yearLabel.font = [UIFont boldSystemFontOfSize:100.0f];
yearLabel.text = @([NSDate date].br_year).stringValue;
[datePickerView.alertView addSubview:yearLabel];
// 滚动选择器,动态更新年份
datePickerView.changeBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
    yearLabel.text = selectDate ? @(selectDate.br_year).stringValue : @"";
};

BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
customStyle.pickerColor = [UIColor clearColor];
datePickerView.pickerStyle = customStyle;

[datePickerView show];

效果

image

295060456 commented 4 years ago

牛批

295060456 commented 3 years ago

作者啊 你把这个封装进去嘛,因为是一体的,别人不要这个可以不传数据啊,外界自己定义,不解耦啊。