Skip to content

Elenionl/ELPickerViewController

Repository files navigation

ELPickerViewController

OBJ-C 可定制选择器

Screenshots

image

How to use

ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleGender contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
  [sender setTitle:chosenString forState:UIControlStateNormal];
}];
[self.view addSubview:controller.view];
[self addChildViewController:controller];

If you are using style default, contentStrings are necessary, keys are not necessary.

If you are using other styles, contentStrings and keys should be nil. If you pass contentStrings or keys, it makes no difference.

The pick result will be given back in pickCompletion. The pickCompletion block will be executed exactly when the user tap the choose button.

When choose button tapped, the picker view and its controller will be automatically removed from their parent view / view controller.

Summary

An easy-use and customizable picker view.

###custom

// default you can customize whatever you like
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleDefault contentStrings:@[@"choose 1", @"choose 2", @"choose 3", @"choose 4",] keys:@[@"1", @"2", @"3", @"4",] pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
  [sender setTitle:chosenString forState:UIControlStateNormal];
  self.keyLabel.text = chosenKey;
}];
// gender picker
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleGender contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
    [sender setTitle:chosenString forState:UIControlStateNormal];
}];
// marriage status picker
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleMarriage contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
    [sender setTitle:chosenString forState:UIControlStateNormal];
}];
// date picker
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleDate contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
    [sender setTitle:chosenString forState:UIControlStateNormal];
}];
// year and month picker
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleYearAndMonth contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
    [sender setTitle:chosenString forState:UIControlStateNormal];
  }];
// country picker
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleCountry contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
  [sender setTitle:chosenString forState:UIControlStateNormal];
}];
// id card picker
ELPickerViewController *controller = [[ELPickerViewController alloc] initWithViewController:self PickerViewStyle:REPickerViewStyleIDCardStyle contentStrings:nil keys:nil pickCompletion:^(NSString *chosenString, NSString *chosenKey) {
    [sender setTitle:chosenString forState:UIControlStateNormal];
  }];

Requirements

  • iOS 8.0+
  • ARC

Author

@Elenionl, stallanxu@gmail.com

License

English: ELPickerViewController is available under the MIT license, see the LICENSE file for more information.

About

An easy-use and modifiable picker view for iOS devices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published