agiapp / BRPickerView

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

Request: Custom units on top #122

Closed skuske closed 4 years ago

skuske commented 4 years ago

I noticed the pickerStyleWithDateUnitOnTop for date pickers, and I was wondering if there is any way to create custom unit strings on top for all other picker styles, too. That would make it easy to create explanations for the displayed picker arrays. Best would be if there was also a way to set font size and style for the unit labels.

Many thanks for this brilliant component! :o)

agiapp commented 4 years ago

Add properties:

/** accessory view for above picker view. default is nil */
@property (nonatomic, strong) UIView *pickerHeaderView;

/** accessory view below picker view. default is nil */
@property (nonatomic, strong) UIView *pickerFooterView;

Usage:

UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
headerView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.1f];
NSArray *unitArr = @[@"年", @"月", @"日"];
for (NSInteger i = 0; i < unitArr.count; i++) {
    CGFloat width = SCREEN_WIDTH / unitArr.count;
    CGFloat orginX = i * (SCREEN_WIDTH / unitArr.count);
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(orginX, 0, width, 36)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:16.0f];
    label.textColor = [UIColor darkGrayColor];
    label.text = unitArr[i];
    [headerView addSubview:label];
}
datePickerView.pickerHeaderView = headerView;

image

skuske commented 4 years ago

@91renb

Many thanks!