ZJPickerView 2.0.2

ZJPickerView 2.0.2

Maintained by Abnerzj.



ZJPickerView

Platform Language License CocoaPods Compatible Weibo Jianshu



Getting Started【开始使用】

Features【能做什么】

  • 一行代码即可集成。
  • 支持任意列数据联动展示。
  • 支持字符串整型浮点型等数据类型。
  • 支持自定义界面中子控件的文字颜色文字字体
  • 支持自定义PickerView的属性:PickerView的高度、PickerView一行的高度、选中内容和未选中内容文字属性、选中行分割线背景颜色。
  • 支持自定义背景透明度和是否接收背景触摸事件。
  • 支持选择完内容回调,每一列选中的值用逗号分隔开。
  • 支持已选择内容是否展示在标题上及展示时是否默认滚动到已选择内容那一行。

Installation【安装】

From CocoaPods【使用CocoaPods】

pod 'ZJPickerView'

Manually【手动导入】

  • Drag all source files under floder ZJPickerView to your project.【将ZJPickerView文件夹中的所有源代码拽入项目中】
  • Import the main header file:#import "ZJPickerView.h"【导入主头文件:#import "ZJPickerView.h"
ZJPickerView.h
ZJPickerView.m
ZJPickerViewProperty.h
ZJPickerViewProperty.m
ZJPickerViewConfig.h
ZJPickerViewConfig.m

Examples【示例】

Direct Use【直接使用】

// 第一种方式:通过自定义配置
[ZJPickerView zj_showWithDataList:@[@"IT", @"销售", @"自媒体", @"游戏主播", @"产品策划"] config:nil completion:^(NSString *selectContent) {
    NSLog(@"ZJPickerView log tip:---> selectContent:%@", selectContent);
}];

// 第二种方式:通过自定义属性
[ZJPickerView zj_showWithDataList:@[@"IT", @"销售", @"自媒体", @"游戏主播", @"产品策划"] propertyDict:nil completion:^(NSString *selectContent) {
    NSLog(@"ZJPickerView log tip:---> selectContent:%@", selectContent);
}];

User-defined properties【自定义想要的PickerView】

第一种方式:通过自定义配置

ZJPickerViewConfig *config = [[ZJPickerViewConfig alloc] init];

config.maskAlpha = 0.5f;
config.isTouchMaskHide = YES;

config.pickerViewHeight = 300.0f;
config.rowHeight = 44.0f;
config.selectRowTitleAttribute = @{NSForegroundColorAttributeName : [UIColor orangeColor], NSFontAttributeName : [UIFont systemFontOfSize:20.0f]};
config.unSelectRowTitleAttribute = @{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName : [UIFont systemFontOfSize:20.0f]};
if (@available(iOS 14.0, *)) {
    config.separatorColor = [[UIColor redColor] colorWithAlphaComponent:0.12];
} else {
    config.separatorColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0 blue:222.0/255.0 alpha:1.0];
}
config.isScrollToSelectedRow = YES;
config.sureBtnTitle = @"完成";
config.sureTextColor = [UIColor orangeColor];
config.sureTextFont = [UIFont systemFontOfSize:17.0];

config.cancelBtnTitle = @"取消呀";
config.cancelTextColor = [UIColor grayColor];
config.cancelTextFont = [UIFont systemFontOfSize:17.0];

config.titleLabelText = [_selectContentLabel.text substringFromIndex:5];
config.titleTextColor = [UIColor darkTextColor];
config.titleTextFont = [UIFont systemFontOfSize:17.0];
config.titleLineColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0 blue:222.0/255.0 alpha:1.0];
config.dividedSymbol = @".";
config.isDividedSelectContent = YES;
config.isShowSelectContent = YES;
config.hiddenTitleLabel = NO;

config.isAnimationShow = YES;

// 2.Show(显示)
__weak typeof(_selectContentLabel) weak_selectContentLabel = _selectContentLabel;
[ZJPickerView zj_showWithDataList:dataList config:config completion:^(NSString *selectContent) {
    NSLog(@"ZJPickerView log tip:---> selectContent:%@", selectContent);

    // show select content
    NSArray *selectStrings = [selectContent componentsSeparatedByString:@","];
    NSMutableString *selectStringCollection = [[NSMutableString alloc] initWithString:@"选择内容:"];
    [selectStrings enumerateObjectsUsingBlock:^(NSString *selectString, NSUInteger idx, BOOL * _Nonnull stop) {
        if (selectString.length && ![selectString isEqualToString:@""]) {
            [selectStringCollection appendString:selectString];
        }
    }];
    weak_selectContentLabel.text = selectStringCollection;
}];

第二种方式:通过自定义属性

// 支持的属性列表
// content: NSString type
extern NSString * _Nonnull const ZJPickerViewPropertyCanceBtnTitleKey; // cance button Title(取消按钮)
extern NSString * _Nonnull const ZJPickerViewPropertySureBtnTitleKey;  // sure button Title(确定按钮)
extern NSString * _Nonnull const ZJPickerViewPropertyTipLabelTextKey;  // tipLabel text(选择提示标签,tips: When multi component, recommended the selected content be separated by commas. 重要提示:多列时建议已选择的内容用英文逗号隔开,参考`ZJPickerViewPropertyIsDividedSelectContentKey`这个key)
extern NSString * _Nonnull const ZJPickerViewPropertyDividedSymbolKey;  // divided symbol, default commas (选中内容的分隔符,默认英文逗号)

// color: UIColor type
extern NSString * _Nonnull const ZJPickerViewPropertyCanceBtnTitleColorKey; // cance button Title color(取消按钮文字颜色)
extern NSString * _Nonnull const ZJPickerViewPropertySureBtnTitleColorKey;  // sure button Title color(确定按钮文字颜色)
extern NSString * _Nonnull const ZJPickerViewPropertyTipLabelTextColorKey;  // tipLabel text color(选择提示标签文字颜色)
extern NSString * _Nonnull const ZJPickerViewPropertyLineViewBackgroundColorKey;  // lineView backgroundColor(顶部工具条分割线背景颜色)

// font: UIFont type
extern NSString * _Nonnull const ZJPickerViewPropertyCanceBtnTitleFontKey; // cance button label font, default 17.0f(取消按钮字体大小)
extern NSString * _Nonnull const ZJPickerViewPropertySureBtnTitleFontKey;  // sure button label font, default 17.0f(确定按钮字体大小)
extern NSString * _Nonnull const ZJPickerViewPropertyTipLabelTextFontKey;  // tipLabel font, default 17.0f(选择提示标题字体大小)

// pickerView:
// CGFloat type
extern NSString * _Nonnull const ZJPickerViewPropertyPickerViewHeightKey;  // pickerView height, default 224 pt(pickerView高度)
extern NSString * _Nonnull const ZJPickerViewPropertyOneComponentRowHeightKey;  // one component row height, default 32 pt(pickerView一行的高度)
// NSDictionary type
extern NSString * _Nonnull const ZJPickerViewPropertySelectRowTitleAttrKey;  // select row titlt attribute(pickerView当前选中的文字颜色)
extern NSString * _Nonnull const ZJPickerViewPropertyUnSelectRowTitleAttrKey;  // unSelect row titlt attribute(pickerView当前没有选中的文字颜色)
// UIColor type
extern NSString * _Nonnull const ZJPickerViewPropertySelectRowLineBackgroundColorKey;  // select row top and bottom line backgroundColor(选中行顶部和底部分割线背景颜色)

// other:
// BOOL type
extern NSString * _Nonnull const ZJPickerViewPropertyIsTouchBackgroundHideKey;  // touch background is hide, default NO(是否点击背景隐藏)
extern NSString * _Nonnull const ZJPickerViewPropertyIsShowTipLabelKey;  // is show tipLabel, default NO. note: if the value of this key`ZJPickerViewPropertyIsShowSelectContentKey` is YES, the value of ZJPickerViewPropertyIsShowTipLabelKey is ignored.(是否显示提示标签。注意,如果这个key`ZJPickerViewPropertyIsShowSelectContentKey`的值为YES,忽略ZJPickerViewPropertyIsShowTipLabelKey的值)
extern NSString * _Nonnull const ZJPickerViewPropertyIsShowSelectContentKey;  // scroll component is update and show select content in tipLabel, default NO(选择内容后是否更新选择提示标签)
extern NSString * _Nonnull const ZJPickerViewPropertyIsScrollToSelectedRowKey;  // when pickerView will show scroll to selected row, default NO. note:`ZJPickerViewPropertyTipLabelTextKey` Must pass by value(将要显示时是否滚动到已选择内容那一行,注意,选择提示标签tipLabel必须传内容,比如之前选择了`北京`,此时就需要传入`北京`)
extern NSString * _Nonnull const ZJPickerViewPropertyIsDividedSelectContentKey;  // the select content is divided by comma symbol when pickerView before show, use string matching for every component if value is nil, default NO.(pickerView显示前,已选择的内容是否已用逗号隔开,默认用选择的内容字符串去匹配每一列选中的内容,如果每一列选中的内容存在相似,会造成滚动到选择的那一行出现问题。比如,总共有两列,选择的内容是:`8.2,8.2`,第一列选择的内容`8.2`在索引2的位置,第二列选择的内容`8.2`在索引4的位置,这个时候如果用默认的匹配规则,则每一列在滚动到已选择那一行时,都只会滚动到索引为2之处)
extern NSString * _Nonnull const ZJPickerViewPropertyIsAnimationShowKey;  // show pickerView is need Animation, default YES(显示pickerView时是否带动画效果)
// CGFloat type
extern NSString * _Nonnull const ZJPickerViewPropertyBackgroundAlphaKey;  // background alpha, default 0.5(0.0~1.0)(背景视图透明度)


// 使用
// 1.Custom propery(自定义属性,根据需要添加想要的属性。PS:如果在多个地方使用到自定义弹框,建议把propertyDict定义为一个宏或全局变量)
NSDictionary *propertyDict = @{ZJPickerViewPropertyCanceBtnTitleKey : @"取消",
                            ZJPickerViewPropertyCanceBtnTitleKey : @"取消",
                            ZJPickerViewPropertyTipLabelTextKey  : @"提示内容",
                            ZJPickerViewPropertyCanceBtnTitleColorKey : [UIColor zj_colorWithHexString:@"#A9A9A9"],
                            ZJPickerViewPropertySureBtnTitleColorKey : [UIColor zj_colorWithHexString:@"#FF6347"],
                            ZJPickerViewPropertyTipLabelTextColorKey : [UIColor zj_colorWithHexString:@"#231F20"],
                            ZJPickerViewPropertyLineViewBackgroundColorKey : [UIColor zj_colorWithHexString:@"#dedede"],
                            ZJPickerViewPropertyCanceBtnTitleFontKey : [UIFont systemFontOfSize:17.0f],
                            ZJPickerViewPropertySureBtnTitleFontKey : [UIFont systemFontOfSize:17.0f],
                            ZJPickerViewPropertyTipLabelTextFontKey : [UIFont systemFontOfSize:17.0f],
                            ZJPickerViewPropertyPickerViewHeightKey : @300.0f,
                            ZJPickerViewPropertyOneComponentRowHeightKey : @40.0f,
                            ZJPickerViewPropertySelectRowTitleAttrKey : @{NSForegroundColorAttributeName : [UIColor zj_colorWithHexString:@"#FF6347"], NSFontAttributeName : [UIFont systemFontOfSize:20.0f]},
                            ZJPickerViewPropertyUnSelectRowTitleAttrKey : @{NSForegroundColorAttributeName : [UIColor zj_colorWithHexString:@"#A9A9A9"], NSFontAttributeName : [UIFont systemFontOfSize:20.0f]},
                            ZJPickerViewPropertySelectRowLineBackgroundColorKey : [UIColor zj_colorWithHexString:@"#dedede"],
                            ZJPickerViewPropertyIsTouchBackgroundHideKey : @YES,
                            ZJPickerViewPropertyIsShowTipLabelKey : @YES,
                            ZJPickerViewPropertyIsShowSelectContentKey : @YES,
                            ZJPickerViewPropertyIsScrollToSelectedRowKey: @YES,
                            ZJPickerViewPropertyIsDividedSelectContentKey: @YES,
                            ZJPickerViewPropertyIsAnimationShowKey : @YES};

// 2.Show(显示)
__weak typeof(_selectContentLabel) weak_selectContentLabel = _selectContentLabel;
[ZJPickerView zj_showWithDataList:dataList propertyDict:propertyDict completion:^(NSString *selectContent) {
    NSLog(@"ZJPickerView log tip:---> selectContent:%@", selectContent);
}];

五、结语

  • 如果在使用过程中遇到BUG,请Issues我,谢谢。
  • 如果你想为ZJPickerView输出代码,请拼命Pull Requests我。
  • 联系我😯简书 微博