BRPickerView icon indicating copy to clipboard operation
BRPickerView copied to clipboard

我帮你加了一个功能

Open JobsKits opened this issue 5 years ago • 3 comments

在 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;

现在就可以背景显示年

JobsKits avatar Aug 02 '20 14:08 JobsKits

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

使用

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

agiapp avatar Aug 06 '20 03:08 agiapp

牛批

JobsKits avatar Aug 06 '20 03:08 JobsKits

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

JobsKits avatar Nov 20 '20 09:11 JobsKits