1. Framework introduction

BRPickerView encapsulates the selector component commonly used in iOS. Highly encapsulated, just a line of code to complete the call, with more flexibility to support custom theme colors. The main types of selectors include date selectors, time selectors, address selectors, and custom string selectors.

Frame address: github.com/91renb/BRPi…

[Special note] :

  • The latest version is:2.2.1
  • If the latest version cannot be found, perform it firstpod setup, after the update is completed; To performpod search BRPickerViewDo a search, and you’ll see the latest version.

2. Effect demonstration

Check and run BRPickerViewDemo xcodeproj

Framework Demo operation effect Figure 1 Framework Demo operation effect Figure 2

3. Update records

  • 2018-04-27 (V2.2.1) :

    • Bug fixes for iPad and landscape display.
    • Optimize code to improve framework adaptability and reduce memory consumption.
  • 2018-04-03 (V2.2.0) :

    • The time picker adds seven new display types (BRDatePickerMode), which can be used selectively according to the needs of your project.
    • It ADAPTS to landscape and the bottom security area of the iPhoneX.
    • Changed the name of the minimum time and maximum time parameter (NSString, NSDate).
    • Fix a bug that appears when comparing time sizes.
  • 2018-03-19 (V2.1.3) :

    • Modify the callback parameters after the address selector is confirmed.
    • The modification is as follows: The name, code and index of a province can be obtained from the model of a province.resultBlock:^(BRProvinceModel *province, BRCityModel *city, BRAreaModel *area) {}
    • Remove third-party dependent librariesMJExtensionTo manually resolve the address data source.
  • 2018-03-11 (V2.1.2) :

    • Renamed the Github user name and updated the path associated with the project. (Tip: Previous versions of POD are not affected)
  • 2018-02-28 (V2.1.1) :

    • Fixed a bug where bundles could not load local data sources (brcity.plist) in some cases.
  • 2018-01-26 (V2.1.0) :

    • Add a method to the address picker (see Method 4) that provides data source parameters and supports external incoming locale data sources.
    • Tip: Pay attention to the data source format, see brcity.json. Json file contents can be placed in the background to maintain, through the background interface to obtain the local data source (the content of the BRCity. Json file).
  • 2018-01-25 (V2.0.0) :

    • The address data source (brcity.plist) has been updated, and the regional information is the latest and most complete in 2018, which is completely consistent with the regional information of wechat.
    • Support to customize the default address selection (format: @[@” Zhejiang “, @” Hangzhou “, @” Xihu “]), support the next click to enter the address picker, the default address is the result of the last selection.
    • Modified interface methods for date pickers, address pickers, and string pickers (removed previous method 2).
    • Added the address selector display type, support three display: show province only, show province and city, show province.
  • 2018-01-05 (V1.3.0) :

    • Add an unselected callback method (cancelBlock is executed by clicking the background or cancel button)

    • The dataSource argument supports two types of data sources:

      1> Can directly pass array: NSArray type;

      2> You can pass the plist file name: NSString, suffix name, plist file content must be array format.

  • 2018-01-02 (V1.2.0) :

    • Adds methods to support custom theme colors.
  • 2017-11-26 (V1.1.0) :

    • Replace third-party dependent libraries.

      The original YYModel was replaced with MJExtension. I did not notice that importing YYModel and importing YYKit at the same time would lead to repeated import and conflict (in addition, when using YYModel, the header file and method name of manual import and POD import are also different, so it is easy to make mistakes).

  • 2017-11-16 (V1.0.0) :

    • Initial version!

4. Install

4.1. CocoaPods

  1. Add pod ‘BRPickerView’ to your Podfile.

  2. Execute pod Install or POD Update.

  3. Import the header file #import < brpickerView.h >.

4.2. Manual import

  1. Drag the BRPickerView folder in the same directory as readme.md into the project

  2. Import the header file #import “brpickerview.h”.

5. System requirements

  • IOS 8.0 +
  • ARC

6. Use

6.1. Time picker:BRDatePickerView

Look at the brdatepickerView.h header file, which provides three methods, you can choose one of them to use according to your needs.

/** * 1. Display time picker ** @param title title * @param dateType Date display type * @param defaultSelValue Time selected by default (value null/value format error) * @param resultBlock selects the result callback * */ + (void)showDatePickerWithTitle:(NSString *)title dateType:(BRDatePickerMode)dateType defaultSelValue:(NSString *)defaultSelValue resultBlock:(BRDateResultBlock)resultBlock; /** * 2. Display time picker (support setting automatic selection and custom theme color) ** @param title * @param dateType Date display type * @param defaultSelValue * @param minDate Minimum time, MinDate (NSDate+BRPickerView) * @param maxDate Maximum time, * @param isAutoSelect whether to automatically select, that is, after selecting (scroll) the result callback, Pass the selected result value * @param themeColor custom themeColor * @param resultBlock select result callback * */ + (void)showDatePickerWithTitle:(NSString *)title dateType:(BRDatePickerMode)dateType defaultSelValue:(NSString *)defaultSelValue minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRDateResultBlock)resultBlock; ** @param title * @param dateType Date display type * @param defaultSelValue * @param minDate Minimum time, MinDate (NSDate+BRPickerView) * @param maxDate Maximum time, * @param isAutoSelect whether to automatically select, that is, after selecting (scroll) the result callback, Pass the selected result value * @param themeColor custom themeColor * @param resultBlock select result callback * @param cancelBlock unselected callback * */ + (void)showDatePickerWithTitle:(NSString *)title dateType:(BRDatePickerMode)dateType defaultSelValue:(NSString *)defaultSelValue minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRDateResultBlock)resultBlock cancelBlock:(BRDateCancelBlock)cancelBlock;Copy the code
  • Usage examples (see Demo) :
NSDate *minDate = [NSDate br_setYear:1990 month:3 day:12]; NSDate *maxDate = [NSDate date]; [BRDatePickerView showDatePickerWithTitle: @ "date of birth" dateType: BRDatePickerModeYMD defaultSelValue: weakSelf. BirthdayTF. The text minDate:minDate maxDate:maxDate isAutoSelect:YES themeColor:nil resultBlock:^(NSString *selectValue) { Weakself.birthdaytf.text = selectValue;} cancelBlock:^{NSLog(@" click background or cancel button ");}]; weakself.birthdaytf.text = selectValue;} cancelBlock:^{NSLog(@" click background or cancel button ");}];Copy the code
  • Display type of time selector:
// type pedef NS_ENUM(NSInteger, BRDatePickerMode) {// -- UIDatePickerModeTime BRDatePickerModeTime // HH:mm // UIDatePickerModeDate BRDatePickerModeDate, // yyyy-MM-dd // UIDatePickerModeDateAndTime BRDatePickerModeDateAndTime, // yyyy-MM-dd HH:mm // UIDatePickerModeCountDownTimer BRDatePickerModeCountDownTimer, // BRDatePickerModeYMDHM, yyyY-MM-DD HH:mm // BRDatePickerModeMDHM, // mm-DD HH: MM // yyyY-MM-DD // year BRDatePickerModeYM, // YYYY // yyyy // date BRDatePickerModeMD, // mm-dd // time BRDatePickerModeHM // HH: MM};Copy the code
  • Time selector display type renderings:

The following four styles are encapsulated using the UIDatePicker class and support circular scrolling

Style 1: BRDatePickerModeTime Style 2: BRDatePickerModeDate
Style 3: BRDatePickerModeDateAndTime Pattern 4: BRDatePickerModeCountDownTimer

The following seven styles are encapsulated using the UIPickerView class.

Style 5: BRDatePickerModeYMDHM Style 6: BRDatePickerModeMDHM
Style 7: BRDatePickerModeYMD Style 8: BRDatePickerModeYM
Style 9: BRDatePickerModeY Style 10: BRDatePickerModeMD
Style 11: BRDatePickerModeHM

6.2. Address picker:BRAddressPickerView

Look at the brAddresspickerView.h header file, which provides four methods, and choose one of them to use according to your needs.

/** * 1. Display address selector ** @param defaultSelectedArr default selected value (pass array, e.g. : @[@" Zhejiang Province ", @" Hangzhou City" @ "depressed"]) * @ param resultBlock choice after the callback * * / + (void) showAddressPickerWithDefaultSelected: (defaultSelectedArr NSArray *) resultBlock:(BRAddressResultBlock)resultBlock; ** @param defaultSelectedArr selects the default value (pass array, e.g. : @param isAutoSelect whether to automatically select, that is, after selecting (scroll) the execution result callback, Pass the selected result value * @param themeColor custom themeColor * @param resultBlock callback after selection * */ + (void)showAddressPickerWithDefaultSelected:(NSArray *)defaultSelectedArr isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRAddressResultBlock)resultBlock; ** @param showType Address picker display type * @param defaultSelectedArr default selected value (pass array, Such as: @param isAutoSelect whether to automatically select, that is, after selecting (scroll) the execution result callback, Pass the selected result value * @param themeColor custom themeColor * @param resultBlock selected callback * @param cancelBlock unselected callback * */ + (void)showAddressPickerWithShowType:(BRAddressPickerMode)showType defaultSelected:(NSArray *)defaultSelectedArr isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRAddressResultBlock)resultBlock cancelBlock:(BRAddressCancelBlock)cancelBlock; ** @param showType address selector display type * @param dataSource local dataSource * @param defaultSelectedArr Default selected value (pass array, e.g. : @param isAutoSelect whether to automatically select, that is, after selecting (scroll) the execution result callback, Pass the selected result value * @param themeColor custom themeColor * @param resultBlock selected callback * @param cancelBlock unselected callback * */ + (void)showAddressPickerWithShowType:(BRAddressPickerMode)showType dataSource:(NSArray *)dataSource defaultSelected:(NSArray *)defaultSelectedArr isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRAddressResultBlock)resultBlock cancelBlock:(BRAddressCancelBlock)cancelBlock;Copy the code
  • Usage examples (see Demo) :
// [transform] : split the string into an array based on the @" "substring, as in: Xihu District, Hangzhou City, Zhejiang Province @ "depressed"] NSArray * defaultSelArr = [weakSelf. AddressTF. Text componentsSeparatedByString: @ ""]. [BRAddressPickerView showAddressPickerWithShowType:BRAddressPickerModeArea defaultSelected:defaultSelArr isAutoSelect:YES themeColor:nil resultBlock:^(BRProvinceModel *province, BRCityModel *city, BRAreaModel *area) { weakSelf.addressTF.text = [NSString stringWithFormat:@"%@ %@ %@", province.name, city.name, } cancelBlock:^{NSLog(@" click background view or cancel button ");}];Copy the code
  • The three display types of address pickers (the three enumerations of showType) :
Style 1: BRAddressPickerModeProvince Style 2: BRAddressPickerModeCity
Style 3: BRAddressPickerModeArea

6.3. Custom string selectors:BRStringPickerView

Take a look at the brStringpickerView.h header file, which provides three methods, one of which you can use according to your needs.

/** * 1. Display custom string selector ** @param title title * @param dataSource dataSource (1). Direct array: type NSArray; 2. You can upload the plist file name: * @param defaultSelValue Specifies the row selected by default (single-column string, Many biographies one-dimensional array) * @ param resultBlock choice after the callback * * / + (void) showStringPickerWithTitle: (nsstrings *) title the dataSource (id) the dataSource defaultSelValue:(id)defaultSelValue resultBlock:(BRStringResultBlock)resultBlock; /** * 2. Display custom string selector (support setting automatic selection and custom theme color) ** @param title title * @param dataSource dataSource (1). Direct array: type NSArray; 2. You can upload the plist file name: * @param defaultSelValue Specifies the row selected by default. * @param isAutoSelect specifies whether the row is automatically selected. That is, after selecting (scrolling) to execute the result callback, The choice of the resulting value * @ param themeColor custom theme colors * @ param resultBlock choice after the callback * * / + (void) showStringPickerWithTitle title: (nsstrings *)  dataSource:(id)dataSource defaultSelValue:(id)defaultSelValue isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRStringResultBlock)resultBlock; ** @param title * @param dataSource dataSource (1). Direct array: type NSArray; 2. You can upload the plist file name: * @param defaultSelValue Specifies the row selected by default. * @param isAutoSelect specifies whether the row is automatically selected. That is, after selecting (scrolling) to execute the result callback, Pass the selected result value * @param themeColor custom themeColor * @param resultBlock selected callback * @param cancelBlock unselected callback * */ + (void)showStringPickerWithTitle:(NSString *)title dataSource:(id)dataSource defaultSelValue:(id)defaultSelValue isAutoSelect:(BOOL)isAutoSelect themeColor:(UIColor *)themeColor resultBlock:(BRStringResultBlock)resultBlock cancelBlock:(BRStringCancelBlock)cancelBlock;Copy the code
  • Usage examples (see Demo) :
/ / custom single string / / NSArray * dataSource = @ [@ "college here," @ "college," @ "undergraduate," @ "master", @, "Dr" @ "postdoctoral"]. NSString *dataSource = @"testData1.plist"; / / data source array (above) can be put in file [BRStringPickerView showStringPickerWithTitle: @ "degree" dataSource: the dataSource defaultSelValue:weakSelf.educationTF.text isAutoSelect:YES themeColor:nil resultBlock:^(id selectValue) { WeakSelf.edu cationTF. Text = selectValue;} cancelBlock: ^ {NSLog (@ "background view or click the cancel button");}]; / / custom columns string NSArray * dataSource = @ [@ [@ "week 1," @ "week 2," @ "3 weeks," @ "4 weeks," @ "week 5," @ "6 weeks," @ "7 weeks"], @ [@ "day 1," @ "2 days", @" 3rd day ", @" 4th day ", @" 5th day ", @" 6th day ", @" 7th day "]]; //NSString *dataSource = @"testData3.plist"; / / data source array (above) can be put in file NSArray * defaultSelArr = [weakSelf. OtherTF. Text componentsSeparatedByString: @ ", "]. [BRStringPickerView showStringPickerWithTitle: @ "custom multi-column string" dataSource: dataSource defaultSelValue: defaultSelArr isAutoSelect:YES themeColor:RGB_HEX(0xff7998, 1.0f) resultBlock:^(id selectValue) {weakself.othertf.text = [NSString stringWithFormat:@"%@, } cancelBlock:^{NSLog(@" click on background view or cancel button ");}];Copy the code
  • String selector effect:
Single-column string selector (default theme color style) Two-column string selector (custom theme color style)
3-column string selector (custom theme color style) 4-column string selector (custom theme color style)

Permit for 7.

BRPickerView uses an MIT LICENSE. See the LICENSE file for details.