### Initialize Multi-Column Text Picker Source: https://github.com/agiapp/brpickerview/blob/master/README.md Basic setup for a multi-column text picker using BRTextPickerComponentMulti mode. ```objective-c /// 多列文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentMulti]; textPickerView.title = @"多列文本选择器"; // 设置数据源 textPickerView.dataSourceArr = @[@[@"语文", @"数学", @"英语"], @[@"优秀", @"良好"]]; textPickerView.selectIndexs = self.mySelectIndexs; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { self.mySelectIndexs = indexs; // 将模型数组元素的 text 属性值,通过分隔符-连接成字符串(组件内封装的工具方法) NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); }; [textPickerView show]; ``` -------------------------------- ### Initialize Cascade Text Picker Source: https://github.com/agiapp/brpickerview/blob/master/README.md Setup for a cascade text picker using BRTextPickerComponentCascade mode with hierarchical data. ```objective-c /// 多列联动文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; textPickerView.title = @"多列联动文本选择器"; NSArray *dataArr = @[ @{ @"text" : @"浙江省", @"children" : @[ @{ @"text": @"杭州市", @"children": @[@{ @"text": @"西湖区" }, @{ @"text": @"滨江区" }] }, @{ @"text": @"宁波市", @"children": @[@{ @"text": @"海曙区" }, @{ @"text": @"江北区" }] }, @{ @"text": @"温州市", @"children": @[@{ @"text": @"鹿城区" }, @{ @"text": @"龙湾区" }] } ] }, @{ @"text" : @"江苏省", @"children" : @[ @{ @"text": @"南京市", @"children": @[@{ @"text": @"玄武区" }, @{ @"text": @"秦淮区" }] }, @{ @"text": @"苏州市", @"children": @[@{ @"text": @"虎丘区" }, @{ @"text": @"吴中区" }] } ] }, @{ @"text" : @"辽宁省", @"children" : @[ @{ @"text": @"沈阳市", @"children": @[@{ @"text": @"沈河区" }, @{ @"text": @"和平区" }] }, @{ @"text": @"大连市", @"children": @[@{ @"text": @"中山区" }, @{ @"text": @"金州区" }] } ] } ]; // 设置数据源:传树状结构模型数组(NSArray *) textPickerView.dataSourceArr = [NSArray br_modelArrayWithJson:dataArr mapper:nil]; textPickerView.selectIndexs = self.mySelectIndexs; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { self.mySelectIndexs = indexs; // 将模型数组元素的 text 属性值,通过-分隔符 连接成字符串(组件内封装的工具方法) NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); }; [textPickerView show]; ``` -------------------------------- ### Initialize and Configure BRDatePickerView Source: https://github.com/agiapp/brpickerview/blob/master/README.md Demonstrates how to instantiate a date picker, configure its properties, apply a custom style, and display it. ```objective-c // 1.创建日期选择器 BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init]; // 2.设置属性 datePickerView.pickerMode = BRDatePickerModeYMD; datePickerView.title = @"选择年月日"; // datePickerView.selectValue = @"2019-10-30"; datePickerView.selectDate = [NSDate br_setYear:2019 month:10 day:30]; datePickerView.minDate = [NSDate br_setYear:1949 month:3 day:12]; datePickerView.maxDate = [NSDate date]; datePickerView.isAutoSelect = YES; datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) { NSLog(@"选择的值:%@", selectValue); }; // 设置自定义样式 BRPickerStyle *customStyle = [[BRPickerStyle alloc]init]; customStyle.pickerColor = BR_RGB_HEX(0xd9dbdf, 1.0f); customStyle.pickerTextColor = [UIColor redColor]; customStyle.separatorColor = [UIColor redColor]; datePickerView.pickerStyle = customStyle; // 3.显示 [datePickerView show]; ``` -------------------------------- ### BRTextPickerView Initialization and Configuration Source: https://github.com/agiapp/brpickerview/blob/master/README.md Initializes a cascading text picker and configures it with a local data source file and display settings. ```APIDOC ## BRTextPickerView Initialization ### Description Initializes the picker in cascade mode and sets the title, data source file, and column display depth. ### Method Objective-C Initialization ### Parameters - **pickerMode** (BRTextPickerComponent) - Required - Set to BRTextPickerComponentCascade for cascading selection. - **title** (NSString) - Optional - The title displayed on the picker. - **fileName** (NSString) - Required - The name of the local JSON file containing the data. - **showColumnNum** (NSInteger) - Optional - The number of columns to display (e.g., 1 for province, 2 for city, 3 for district). - **selectIndexs** (NSArray) - Optional - The initial selection indices. - **multiResultBlock** (Block) - Required - Callback triggered upon selection, returning selected models and indices. ### Usage Example ```objective-c BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; textPickerView.title = @"请选择地区"; textPickerView.fileName = @"region_tree_data.json"; textPickerView.showColumnNum = 3; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); }; [textPickerView show]; ``` ``` -------------------------------- ### 配置数据源方式 2:plist 文件 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 通过指定本地 plist 文件名来加载数据源。 ```objective-c // 方式2:直接传入 plist 文件名(可以将上面的字符串数组放到本地plist文件中,如:education_data.plist) textPickerView.fileName = @"education_data.plist"; ``` -------------------------------- ### Integrate BRPickerView via CocoaPods Source: https://github.com/agiapp/brpickerview/blob/master/README.md Use these commands in your Podfile to integrate the full library or specific picker components. ```ruby pod 'BRPickerView' ``` ```ruby pod 'BRPickerView/DatePickerView' ``` ```ruby pod 'BRPickerView/AddressPickerView' ``` ```ruby pod 'BRPickerView/StringPickerView' ``` -------------------------------- ### Multi-Column Picker Data Source Options Source: https://github.com/agiapp/brpickerview/blob/master/README.md Three ways to provide data to the multi-column picker: array of arrays, plist file, or model array. ```objective-c // 方式1:多维字符串数组 textPickerView.dataSourceArr = @[@[@"语文", @"数学", @"英语"], @[@"优秀", @"良好"]]; ``` ```objective-c // 方式2:直接传入 plist 文件名(可以将上面的数组放到本地plist文件中,如:grade_level_data.plist) textPickerView.fileName = @"grade_level_data.plist"; ``` ```objective-c // 方式3:传入多维模型数组 NSArray *subjectDataArr = @[@{@"subject_id": @"11", @"subject": @"语文"}, @{@"subject_id": @"12", @"subject": @"数学"}, @{@"subject_id": @"13", @"subject": @"英语"}]; NSArray *gradeDataArr = @[@{@"grade_id": @"1", @"grade": @"优秀"}, @{@"grade_id": @"2", @"grade": @"良好"}]; // 将上面数组 转为 模型数组(组件内封装的工具方法) NSArray *subjectModelArr = [NSArray br_modelArrayWithJson:subjectDataArr mapper:@{ @"code": @"subject_id", @"text": @"subject" }]; NSArray *gradeModelArr = [NSArray br_modelArrayWithJson:gradeDataArr mapper:@{ @"code": @"grade_id", @"text": @"grade" }]; textPickerView.dataSourceArr = @[subjectModelArr, gradeModelArr]; ``` -------------------------------- ### 配置数据源方式 1:字符串数组 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 直接通过字符串数组设置选择器的数据源。 ```objective-c // 方式1:传字符串数组 textPickerView.dataSourceArr = @[@"大专以下", @"大专", @"本科", @"硕士", @"博士", @"博士后"]; ``` -------------------------------- ### BRTextPickerView (Cascade Mode) Source: https://github.com/agiapp/brpickerview/blob/master/README.md Initializes and configures a multi-column cascade text picker. It demonstrates how to map JSON data to models, build a tree structure, and handle selection callbacks. ```APIDOC ## BRTextPickerView (Cascade Mode) ### Description Initializes a multi-column cascade text picker. It requires mapping raw JSON data to `BRTextModel` objects and converting them into a tree structure before assigning to `dataSourceArr`. ### Usage 1. Initialize with `BRTextPickerComponentCascade` mode. 2. Map JSON keys to `BRTextModel` properties using a dictionary. 3. Convert flat array to tree structure using `br_buildTreeArray`. 4. Set `dataSourceArr` and define `multiResultBlock` to handle user selection. ### Example ```objective-c BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; NSDictionary *mapper = @{ @"parentCode": @"ParentID", @"code": @"CategoryID", @"text": @"CategoryName" }; NSArray *listModelArr = [NSArray br_modelArrayWithJson:dataArr mapper:mapper]; NSArray *treeModelArr = [listModelArr br_buildTreeArray]; textPickerView.dataSourceArr = treeModelArr; [textPickerView show]; ``` ``` -------------------------------- ### Customize Multi-Column Picker Style Source: https://github.com/agiapp/brpickerview/blob/master/README.md Configure column width, spacing, and text appearance using BRPickerStyle. ```objective-c /// 多列文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentMulti]; textPickerView.title = @"自定义多列字符串"; textPickerView.dataSourceArr = @[@[@"01", @"02", @"03", @"04", @"05", @"06", @"07", @"08", @"09", @"10", @"11", @"12"], @[@"00", @"10", @"20", @"30", @"40", @"50"]]; textPickerView.selectIndexs = self.mySelectIndexs; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { self.mySelectIndexs = indexs; // 将模型数组元素的 text 属性值,通过:分隔符 连接成字符串(组件内封装的工具方法) NSString *selectText = [models br_joinText:@":"]; NSLog(@"选择的结果:%@", selectText); }; // 设置自定义样式 BRPickerStyle *customStyle = [[BRPickerStyle alloc]init]; // 设置 picker 的列宽 customStyle.columnWidth = 30; // 设置 picker 的列间隔 customStyle.columnSpacing = 60; // 设置圆角矩形背景 // 方式1:使用系统自带样式,保留iOS14之后系统默认的圆角样式。 customStyle.clearPickerNewStyle = NO; // 方式2:可以使用UIView自定义一个圆角矩形视图rectView,并添加到 alertView 上也能实现同样的效果([textPickerView.alertView addSubview:rectView];) // 设置选择器中间选中行的样式 customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:20.0f]; customStyle.selectRowTextColor = [UIColor blueColor]; textPickerView.pickerStyle = customStyle; [textPickerView show]; ``` -------------------------------- ### 初始化单列文本选择器 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 展示了如何初始化 BRTextPickerView 并设置基础属性、数据源以及选择结果回调。 ```objective-c /// 单列文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentSingle]; textPickerView.title = @"学历"; // 设置数据源 textPickerView.dataSourceArr = @[@"大专以下", @"大专", @"本科", @"硕士", @"博士", @"博士后"]; textPickerView.selectIndex = self.mySelectIndex; textPickerView.singleResultBlock = ^(BRTextModel * _Nullable model, NSInteger index) { NSLog(@"选择的值:%@", model.text); self.mySelectIndex = index; textField.text = model.text; }; [textPickerView show]; ``` -------------------------------- ### 使用本地数据源配置 BRTextPickerView Source: https://github.com/agiapp/brpickerview/blob/master/README.md 通过设置 fileName 属性加载本地 JSON 文件,并使用 showColumnNum 控制显示的层级列数。 ```objective-c // 地区 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; textPickerView.title = @"请选择地区"; // 设置数据源:传入本地json文件名(可以下载Demo中的 region_tree_data.json 文件放到自己的项目中) textPickerView.fileName = @"region_tree_data.json"; // 设置选择器显示的列数(即层级数),默认是根据数据源层级动态计算显示。如:设置1则只显示前1列数据(即只显示省);设置2则只显示前2列数据(即只显示省、市);设置3则只显示前3列数据(即显示省、市、区) textPickerView.showColumnNum = 3; textPickerView.selectIndexs = self.addressSelectIndexs; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { self.addressSelectIndexs = indexs; // 将模型数组元素的 text 属性值,通过-分隔符 连接成字符串(组件内封装的工具方法) NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); textField.text = selectText; }; [textPickerView show]; ``` -------------------------------- ### 自定义模型属性映射 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 当字典 key 与 BRTextModel 属性不匹配时,通过 mapper 字典指定映射关系。 ```objective-c /// 单列文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentSingle]; textPickerView.title = @"融资情况"; // 方式3:传入一维模型数组(NSArray *) NSArray *dataArr = @[@{@"key": @"1001", @"value": @"无融资", @"remark": @""}, @{@"key": @"2001", @"value": @"天使轮", @"remark": @""}, @{@"key": @"3001", @"value": @"A轮", @"remark": @""}, @{@"key": @"4001", @"value": @"B轮", @"remark": @""}, @{@"key": @"5001", @"value": @"C轮以后", @"remark": @""}, @{@"key": @"6001", @"value": @"已上市", @"remark": @""}]; // 指定 BRTextModel模型的属性 与 字典key 的映射关系 NSDictionary *mapper = @{ @"code": @"key", @"text": @"value", @"extras": @"remark" }; // 将上面数组 转为 模型数组(组件内封装的工具方法) NSArray *modelArr = [NSArray br_modelArrayWithJson:dataArr mapper:mapper]; textPickerView.dataSourceArr = modelArr; textPickerView.singleResultBlock = ^(BRTextModel * _Nullable model, NSInteger index) { NSLog(@"选择的值:%@", model.text); }; [textPickerView show]; ``` -------------------------------- ### 配置网络请求数据源 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 通过定义 mapper 字典将网络返回的 JSON 字段映射到 BRTextModel 模型,并设置 dataSourceArr。 ```objective-c /// 多列联动文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; textPickerView.title = @"多列联动文本选择器"; // 接收网络请求结果数据(下面省略号表示省略部分代码) NSArray *dataArr = ...... responseObject[@"data"]; // 指定 BRTextModel模型的属性 与 字典key 的映射关系 NSDictionary *mapper = @{ @"code": @"adcode", @"text": @"name", @"children": @"districts" }; // 将上面数组 转为 模型数组(组件内封装的工具方法) NSArray *modelArr = [NSArray br_modelArrayWithJson:dataArr mapper:mapper]; textPickerView.dataSourceArr = modelArr; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { // 将模型数组元素的 text 属性值,通过-分隔符 连接成字符串(组件内封装的工具方法) NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); }; [textPickerView show]; ``` -------------------------------- ### Configure Date Picker Style Template 1 Source: https://github.com/agiapp/brpickerview/blob/master/README.md Sets the theme color for the date picker view. ```objective-c datePickerView.pickerStyle = [BRPickerStyle pickerStyleWithThemeColor:[UIColor blueColor]]; ``` -------------------------------- ### 多列联动文本选择器 Objective-C 实现 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 演示了如何初始化 BRTextPickerView,将扁平数据转换为树状结构,并配置样式及回调。 ```objective-c /// 多列联动文本选择器 BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; textPickerView.title = @"多列联动文本选择器"; // 接收网络请求结果数据(下面省略号表示省略部分代码) NSArray *dataArr = ...... responseObject[@"Result"]; // 指定 BRTextModel模型的属性 与 字典key 的映射关系 NSDictionary *mapper = @{ @"parentCode": @"ParentID", @"code": @"CategoryID", @"text": @"CategoryName" }; // 1.先将上面数组 转为 模型数组(组件内封装的工具方法)。如果数据源是多个数组,需要自己先手动组装成一个NSArray类型的扁平结构模型数组。 NSArray *listModelArr = [NSArray br_modelArrayWithJson:dataArr mapper:mapper]; // 2.将扁平结构模型数组 转成 树状结构模型数组(组件内封装的工具方法) NSArray *treeModelArr = [listModelArr br_buildTreeArray]; textPickerView.dataSourceArr = treeModelArr; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { // 将模型数组元素的 text 属性值,通过-分隔符 连接成字符串(组件内封装的工具方法) NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); // 获取选择模型指定属性(如:code)组成的数组(组件内封装的工具方法) NSArray *selectIDs = [models br_getValueArr:@"code"]; }; // 设置选择器中间选中行的样式 BRPickerStyle *customStyle = [[BRPickerStyle alloc]init]; customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:20.0f]; customStyle.selectRowTextColor = [UIColor blueColor]; customStyle.columnWidth = 80; customStyle.columnSpacing = 10; textPickerView.pickerStyle = customStyle; [textPickerView show]; ``` -------------------------------- ### 配置数据源方式 3:模型数组 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 通过传入一维模型数组设置数据源,使用组件内置工具方法进行转换。 ```objective-c // 方式3:传入一维模型数组(NSArray *) NSArray *dataArr = @[@{@"code": @"1", @"text": @"大专以下"}, @{@"code": @"2", @"text": @"大专"}, @{@"code": @"3", @"text": @"本科"}, @{@"code": @"4", @"text": @"硕士"}, @{@"code": @"5", @"text": @"博士"}, @{@"code": @"6", @"text": @"博士后"}]; // 将上面数组 转为 模型数组(组件内封装的工具方法) NSArray *modelArr = [NSArray br_modelArrayWithJson:dataArr mapper:nil]; textPickerView.dataSourceArr = modelArr; ``` -------------------------------- ### 添加选择器到指定容器视图 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 通过 addPickerToView 方法将选择器嵌入到自定义视图中,适用于需要个性化弹框样式的场景。 ```objective-c /// 扩展一:添加选择器到指定容器视图上 /// 应用场景:可将中间的滚轮选择器 pickerView 视图(不包含蒙层及标题栏)添加到任何自定义视图上(会自动填满容器视图),也方便自定义更多的弹框样式 /// 补充说明:如果是自定义确定按钮,需要回调默认选择的值:只需在自定义确定按钮的点击事件方法里执行一下 doneBlock 回调(目的是去触发组件内部执行 resultBlock 回调,进而回调默认选择的值) /// @param view 容器视图 - (void)addPickerToView:(nullable UIView *)view; ``` -------------------------------- ### BRTextPickerView - Multi-column Selection Source: https://github.com/agiapp/brpickerview/blob/master/README.md Initializes and displays a multi-column text picker. Data sources can be provided as multi-dimensional arrays, plist files, or model arrays. ```APIDOC ## BRTextPickerView (BRTextPickerComponentMulti) ### Description Initializes a multi-column text picker view. Users can configure the data source using arrays, plist files, or model objects and handle selection results via a block. ### Method [[BRTextPickerView alloc] initWithPickerMode:BRTextPickerComponentMulti] ### Parameters - **title** (NSString) - The title displayed on the picker. - **dataSourceArr** (NSArray) - The data source for the picker columns. - **fileName** (NSString) - Optional: The name of a local plist file to load data from. - **selectIndexs** (NSArray) - The initial selected indices. - **multiResultBlock** (void(^)(NSArray *models, NSArray *indexs)) - Callback executed when a selection is made. ### Usage Example ```objective-c BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentMulti]; textPickerView.title = @"多列文本选择器"; textPickerView.dataSourceArr = @[@[@"语文", @"数学", @"英语"], @[@"优秀", @"良好"]]; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); }; [textPickerView show]; ``` ``` -------------------------------- ### Configure Date Picker Style Template 3 Source: https://github.com/agiapp/brpickerview/blob/master/README.md Sets a custom image for the 'Done' button in the date picker view. ```objective-c datePickerView.pickerStyle = [BRPickerStyle pickerStyleWithDoneBtnImage:[UIImage imageNamed:@"icon_close"]]; ``` -------------------------------- ### Handling Network Data with BRTextPickerView Source: https://github.com/agiapp/brpickerview/blob/master/README.md Configures the picker to use data fetched from a network API by mapping dictionary keys to BRTextModel properties. ```APIDOC ## BRTextPickerView Network Data Configuration ### Description Maps network response data to the picker's model structure using a mapper dictionary. ### Method Objective-C Configuration ### Parameters - **mapper** (NSDictionary) - Required - Defines the mapping between BRTextModel properties (code, text, children) and the API response keys. - **dataSourceArr** (NSArray) - Required - The array of models converted from the API response. ### Usage Example ```objective-c BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; NSDictionary *mapper = @{ @"code": @"adcode", @"text": @"name", @"children": @"districts" }; NSArray *modelArr = [NSArray br_modelArrayWithJson:dataArr mapper:mapper]; textPickerView.dataSourceArr = modelArr; [textPickerView show]; ``` ``` -------------------------------- ### Configure Date Picker Style Template 2 Source: https://github.com/agiapp/brpickerview/blob/master/README.md Sets the text color for the 'Done' button in the date picker view. ```objective-c datePickerView.pickerStyle = [BRPickerStyle pickerStyleWithDoneTextColor:[UIColor blueColor]]; ``` -------------------------------- ### BRTextPickerView - Cascading Selection Source: https://github.com/agiapp/brpickerview/blob/master/README.md Initializes and displays a cascading text picker for hierarchical data structures. ```APIDOC ## BRTextPickerView (BRTextPickerComponentCascade) ### Description Initializes a cascading text picker view for hierarchical data (e.g., Province -> City -> District). The data source must be a tree-structured model array. ### Method [[BRTextPickerView alloc] initWithPickerMode:BRTextPickerComponentCascade] ### Parameters - **title** (NSString) - The title displayed on the picker. - **dataSourceArr** (NSArray) - The tree-structured data source. - **selectIndexs** (NSArray) - The initial selected indices. - **multiResultBlock** (void(^)(NSArray *models, NSArray *indexs)) - Callback executed when a selection is made. ### Usage Example ```objective-c BRTextPickerView *textPickerView = [[BRTextPickerView alloc]initWithPickerMode:BRTextPickerComponentCascade]; textPickerView.title = @"多列联动文本选择器"; textPickerView.dataSourceArr = [NSArray br_modelArrayWithJson:dataArr mapper:nil]; textPickerView.multiResultBlock = ^(NSArray * _Nullable models, NSArray * _Nullable indexs) { NSString *selectText = [models br_joinText:@"-"]; NSLog(@"选择的结果:%@", selectText); }; [textPickerView show]; ``` ``` -------------------------------- ### Define Text Picker Modes Source: https://github.com/agiapp/brpickerview/blob/master/README.md Enumeration defining the available types for BRTextPickerView. ```objective-c /// 文本选择器类型 typedef NS_ENUM(NSInteger, BRTextPickerMode) { /** 单列选择器 */ BRTextPickerComponentSingle, /** 多列选择器 */ BRTextPickerComponentMulti, /** 多列联动选择器 */ BRTextPickerComponentCascade }; ``` -------------------------------- ### 多列联动文本选择器 JSON 数据结构 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 展示了多列联动选择器所需的数据格式,包含 ParentID、CategoryID 和 CategoryName 等字段。 ```json { "Code" : 200, "Msg" : "获取成功", "Result" : [ { "ParentID" : "-1", "ParentName" : "", "CategoryID" : "330000", "CategoryName" : "浙江省" }, { "ParentID" : "-1", "ParentName" : "", "CategoryID" : "320000", "CategoryName" : "江苏省" }, { "ParentID" : "-1", "ParentName" : "", "CategoryID" : "210000", "CategoryName" : "辽宁省" }, { "ParentID" : "330000", "ParentName" : "浙江省", "CategoryID" : "330100", "CategoryName" : "杭州市" }, { "ParentID" : "330000", "ParentName" : "浙江省", "CategoryID" : "330200", "CategoryName" : "宁波市" }, { "ParentID" : "330000", "ParentName" : "浙江省", "CategoryID" : "330300", "CategoryName" : "温州市" }, { "ParentID" : "320000", "ParentName" : "江苏省", "CategoryID" : "320100", "CategoryName" : "南京市" }, { "ParentID" : "320000", "ParentName" : "江苏省", "CategoryID" : "320500", "CategoryName" : "苏州市" }, { "ParentID" : "210000", "ParentName" : "辽宁省", "CategoryID" : "210100", "CategoryName" : "沈阳市" }, { "ParentID" : "210000", "ParentName" : "辽宁省", "CategoryID" : "210200", "CategoryName" : "大连市" } ] } ``` -------------------------------- ### Configure Date Picker Selection Row Style Source: https://github.com/agiapp/brpickerview/blob/master/README.md Use BRPickerStyle to customize the appearance of the selected row in the date picker, including background color, font, and text color. ```objective-c // 设置选择器中间选中行的样式 BRPickerStyle *customStyle = [[BRPickerStyle alloc]init]; customStyle.selectRowColor = [UIColor blueColor]; customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:20.0f]; customStyle.selectRowTextColor = [UIColor redColor]; datePickerView.pickerStyle = customStyle; ``` -------------------------------- ### addPickerToView: Source: https://github.com/agiapp/brpickerview/blob/master/README.md Allows embedding the picker's internal滚轮 (pickerView) directly into a custom container view, bypassing the default modal presentation. ```APIDOC ## addPickerToView: ### Description Adds the picker view (excluding the modal overlay and title bar) to a specified container view. This is useful for custom UI layouts where the picker needs to be embedded directly. ### Method - (void)addPickerToView:(nullable UIView *)view; ### Parameters - **view** (UIView) - The container view where the picker will be added. ``` -------------------------------- ### 处理树状结构数据示例 Source: https://github.com/agiapp/brpickerview/blob/master/README.md 展示了用于多列联动选择器的树状 JSON 数据结构。 ```json { "code": "200", "message": "OK", "data": [ { "adcode": "330000", "name": "浙江省", "districts" : [ { "adcode" : "330100", "name": "杭州市", "districts": [{ "adcode" : "330106", "name": "西湖区" }, { "adcode" : "330108", "name": "滨江区" }] }, { "adcode" : "330200", "name": "宁波市", "districts": [{ "adcode" : "330203", "name": "海曙区" }, { "adcode" : "330205", "name": "江北区" }] }, { "adcode" : "330300", "name": "温州市", "districts": [{ "adcode" : "330302", "name": "鹿城区" }, { "adcode" : "330303", "name": "龙湾区" }] } ] }, { "adcode": "320000", "name": "江苏省", "districts" : [ { "adcode" : "320100", "name": "南京市", "districts": [{ "adcode" : "320102", "name": "玄武区" }, { "adcode" : "320104", "name": "秦淮区" }] }, { "adcode" : "320500", "name": "苏州市", "districts": [{ "adcode" : "320505", "name": "虎丘区" }, { "adcode" : "320506", "name": "吴中区" }] } ] }, { "adcode": "210000", "name": "辽宁省", "districts" : [ { "adcode" : "210100", "name": "沈阳市", "districts": [{ "adcode" : "210103", "name": "沈河区" }, { "adcode" : "210102", "name": "和平区" }] }, { "adcode" : "210200", "name": "大连市", "districts": [{ "adcode" : "210202", "name": "中山区" }, { "adcode" : "210213", "name": "金州区" }] } ] } ] } ``` -------------------------------- ### Add Custom Header View to Date Picker Source: https://github.com/agiapp/brpickerview/blob/master/README.md Creates and assigns a custom UIView as the header for the date picker. ```objective-c // 添加选择器头视图(pickerHeaderView) 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; ``` -------------------------------- ### Address Picker Result Callback Source: https://github.com/agiapp/brpickerview/blob/master/README.md The callback block for the address picker, providing models for province, city, and area. ```objective-c resultBlock:^(BRProvinceModel *province, BRCityModel *city, BRAreaModel *area) {} ``` -------------------------------- ### Define BRDatePickerMode Enum Source: https://github.com/agiapp/brpickerview/blob/master/README.md Defines the available date picker modes, including system-compatible styles and custom formats. ```objective-c /// 日期选择器格式 typedef NS_ENUM(NSInteger, BRDatePickerMode) { // ----- 以下4种是系统样式(兼容国际化日期格式) ----- /** 【yyyy-MM-dd】UIDatePickerModeDate(美式日期:MM-dd-yyyy;英式日期:dd-MM-yyyy)*/ BRDatePickerModeDate, /** 【yyyy-MM-dd HH:mm】 UIDatePickerModeDateAndTime */ BRDatePickerModeDateAndTime, /** 【HH:mm】UIDatePickerModeTime */ BRDatePickerModeTime, /** 【HH:mm】UIDatePickerModeCountDownTimer */ BRDatePickerModeCountDownTimer, // ----- 以下14种是自定义样式 ----- /** 【yyyy-MM-dd HH:mm:ss】年月日时分秒 */ BRDatePickerModeYMDHMS, /** 【yyyy-MM-dd HH:mm】年月日时分 */ BRDatePickerModeYMDHM, /** 【yyyy-MM-dd HH】年月日时 */ BRDatePickerModeYMDH, /** 【MM-dd HH:mm】月日时分 */ BRDatePickerModeMDHM, /** 【yyyy-MM-dd】年月日(兼容国际化日期:dd-MM-yyyy)*/ BRDatePickerModeYMD, /** 【yyyy-MM】年月(兼容国际化日期:MM-yyyy)*/ BRDatePickerModeYM, /** 【yyyy】年 */ BRDatePickerModeY, /** 【MM-dd】月日 */ BRDatePickerModeMD, /** 【HH:mm:ss】时分秒 */ BRDatePickerModeHMS, /** 【HH:mm】时分 */ BRDatePickerModeHM, /** 【mm:ss】分秒 */ BRDatePickerModeMS, /** 【yyyy-qq】年季度 */ BRDatePickerModeYQ, /** 【yyyy-MM-ww】年月周 */ BRDatePickerModeYMW, /** 【yyyy-ww】年周 */ BRDatePickerModeYW }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.