I want to display a picker view and a done button above the picker view .
I have a custom label which will become first responder . So when it becomes first responder I am displaying a picker view as the input view for my label.
Now I want to have a done button on the picker to dismiss the picker view. I played with the inputAccesoryView property of UIPickerView but did not succeed . inputAccessoryView is possible with UITextView , not sure about the UIPickerView . Here is the link for how it can be done with UITextView
UITextView with “Done” button and “Return” key?
Has any body tried this , if someone knows how to do this for picker , please answer.
Thank you all in advance !!
Add your picker view to an action sheet. First of all make sure youre view controller impliments UIPickerViewDelegate and UIActionSheetDelegate.
Then add this method, and call it when you want to show your picker.
- (void)showPicker {
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Pick Value"
delegate:self
cancelButtonTitle:@"Done"
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,180,0,0)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[menu addSubview:pickerView];
[menu showInView:self.view.superview];
//Change the height value in your CGRect to change the size of the actinsheet
[menu setBounds:CGRectMake(0,0,320, 615)];
[pickerView release];
[menu release];
}
I think you can try to put the picker inside a view with a 'Done' button and present that view
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With