//First declare all the property and set the delegate and datasource in .h like this
@interface RegistrationView : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate,UIActionSheetDelegate>
{
UIPickerView *picker;
UIToolbar *toolbarPicker;
UIActionSheet *actionPicker;
}
@property (strong,nonatomic) UIPickerView *picker;
@property (strong,nonatomic) UIToolbar *toolbarPicker;
@property (strong,nonatomic) UIActionSheet *actionPicker;
//and synthesis in .m file
@synthesize picker,actionPicker,toolbarPicker;
// in View did load method put call the setting method for picker
[self pickerSetting];
// set picker,action sheet and toolbar through This method
-(void) pickerSetting
{
toolbarPicker = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,44)];
if (!g_IS_IOS_6)
{
toolbarPicker.barTintColor = [UIColor colorWithRed:72.0/255.0 green:197.0/255.0 blue:87.0/255.0 alpha:1.0];
}
toolbarPicker.frame=CGRectMake(0,0,320,44);
actionPicker = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionPicker.frame = CGRectMake(0, 234, 320, 256);
[actionPicker setActionSheetStyle:UIActionSheetStyleDefault];
actionPicker.delegate = self;
UIImage *imgbtnConvert = [UIImage imageNamed:@"info_button.png"];//Done btn.png
UIButton *btnConvert = [UIButton buttonWithType:UIButtonTypeCustom];
btnConvert.bounds = CGRectMake(200, 0, 93,31);
[btnConvert setTitle:@"Done" forState:UIControlStateNormal];
[btnConvert setTintColor:[UIColor whiteColor]];
[btnConvert setBackgroundImage:imgbtnConvert forState:UIControlStateNormal];
[btnConvert addTarget:self action:@selector(pickerDoneClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItemConvert = [[UIBarButtonItem alloc] initWithCustomView:btnConvert];
UIBarButtonItem *flexConvert = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIImage *imageConvert = [UIImage imageNamed:@"info_button.png"];//cancel png
UIButton *buttonConvert = [UIButton buttonWithType:UIButtonTypeCustom];
buttonConvert.bounds = CGRectMake( 0, 0, 93,31);
[buttonConvert setTitle:@"Cancel" forState:UIControlStateNormal]; //set title
[buttonConvert setTintColor:[UIColor whiteColor]]; //font color
[buttonConvert setBackgroundImage:imageConvert forState:UIControlStateNormal]; //set background image
[buttonConvert addTarget:self action:@selector(pickerCancelClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barCancelButtonItemConvert = [[UIBarButtonItem alloc] initWithCustomView:buttonConvert];
NSArray *itemsConvert = [[NSArray alloc] initWithObjects:barCancelButtonItemConvert, flexConvert, barButtonItemConvert, nil];
[toolbarPicker setItems:itemsConvert];
[actionPicker addSubview:toolbarPicker];
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
picker.backgroundColor= [UIColor whiteColor];
[actionPicker addSubview:picker];
}
// and add two mehtod for picker done button and cancel button click .
-(void) pickerDoneClick
{
// picker done button click put here your code ..
[actionPickerSearchCar dismissWithClickedButtonIndex:0 animated:YES];
}
-(void) pickerCancelClick {
// Cancel button click
[actionPickerSearchCar dismissWithClickedButtonIndex:0 animated:YES];
}
// and put the delegate and data source method
#pragma mark -
#pragma mark UIPickerView Delegate Datasource Method
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
// return yourarr.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
// return yourarr[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// selectedfiles =yourarr[row];
}
// call this method for allocation picker .
[self pickerSetting]
// and show picker using this (put This in button action method)
-(IBAction)showPicker:(id)sender
{
[actionPickerSearchCar showInView:self.view];
[actionPickerSearchCar setBounds:CGRectMake(0, 0, 320, 465)];
}
I hope , it's helpful for you . Thank you.