agiapp / BRPickerView

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

暗黑模式下设置白色不生效 #162

Closed coooliang closed 4 years ago

coooliang commented 4 years ago

暗黑模式下设置白色不生效,我看是因为BRDatePickerView+BR.m的方法中的self.pickerStyle.selectRowColor为nil啊

- (void)setupPickerSelectRowStyle:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    // 1.设置分割线的颜色
    for (UIView *subView in pickerView.subviews) {
        if (subView && [subView isKindOfClass:[UIView class]] && subView.frame.size.height <= 1) {
            subView.backgroundColor = self.pickerStyle.separatorColor;
        }
    }

    // 2.设置选择器中间选中行的背景颜色
    if (self.pickerStyle.selectRowColor) {//nil

我是这样调用的:

BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:[UIColor whiteColor]];
    customStyle.titleBarColor = [UIColor whiteColor];
    customStyle.doneColor = [UIColor whiteColor];
    customStyle.doneTextColor = [UIColor blackColor];
    customStyle.cancelColor = [UIColor whiteColor];
    customStyle.cancelTextColor = [UIColor blackColor];
    customStyle.titleLineColor = [UIColor whiteColor];
    customStyle.titleTextColor = [UIColor grayColor];

    customStyle.pickerColor = [UIColor whiteColor];
    customStyle.pickerTextColor = [UIColor blackColor];
    customStyle.alertViewColor = [UIColor whiteColor];;

    customStyle.selectRowColor = [UIColor blackColor];
    customStyle.separatorColor = [UIColor blackColor];

    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerStyle = customStyle;
    datePickerView.title = @"请选择日期";
    datePickerView.selectDate = [NSDate date];
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {

    };
    [datePickerView show];
coooliang commented 4 years ago

只支持UIPickerView不支持UIDatePicker是吗?

agiapp commented 4 years ago

是的呢,UIDatePicker是系统样式,目前只支持自定义UIPickerView的样式

agiapp commented 4 years ago

设置一下日期的mode

datePickerView.pickerMode = BRDatePickerModeYMD;
coooliang commented 4 years ago

设置一下日期的mode

datePickerView.pickerMode = BRDatePickerModeYMD;

非常感谢,没想到这么快就回复我了!~ 确实可行

BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
    customStyle.titleBarColor = [UIColor whiteColor];
    customStyle.doneColor = [UIColor whiteColor];
    customStyle.doneTextColor = [UIColor blackColor];
    customStyle.cancelColor = [UIColor whiteColor];
    customStyle.cancelTextColor = [UIColor blackColor];
    customStyle.titleLineColor = [UIColor whiteColor];
    customStyle.titleTextColor = [UIColor grayColor];

    customStyle.pickerColor = [UIColor whiteColor];
    customStyle.alertViewColor = [UIColor whiteColor];

    customStyle.selectRowTextColor = [UIColor blackColor];
    customStyle.selectRowColor = [UIColor whiteColor];
    customStyle.separatorColor = [UIColor grayColor];
    customStyle.pickerTextColor = [UIColor blackColor];

    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerMode = BRDatePickerModeYMD;
    datePickerView.pickerStyle = customStyle;
    datePickerView.title = @"请选择日期";
    datePickerView.selectDate = [NSDate date];
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {

    };
    [datePickerView show];

image