Hi!I want to add Toolbar on the upperside of PickerView and want to add one BarButton on the Toolbar Dynamically and on the click event of that button i want to dismiss the Picker as well as toolbar so please help me in this task...Thanks in Advance..
A:
You can create the UIToolBar and its buttons this way -
UIToolbar * toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 324.0f, 320.0f, 44.0f)];
[toolBar setBarStyle:UIBarStyleBlackTranslucent];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissPicker:)];
[toolBar setItems:[NSArray arrayWithObjects:flexibleSpace, doneBtn, nil] animated:YES];
[flexibleSpace release];
[editButton release];
You can add the done button and call a method on tap of this button, in this method you can dismiss the UIPickerView.
Saurabh
2010-07-20 11:29:16
Yes,Thanks for Reply.....
Ankit Vyas
2010-07-20 11:50:17
i want black barbutton instead of Blue.
Ankit Vyas
2010-07-22 09:29:41
According to iPhone HIG "Done" button should be blue. but if you want to add custom button, create a view then add a button in this view and add this view in barbutton item like this - UIView *leftBarButtons = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 10.0f, 200.0f, 34.0f)];// add button in this leftBarButton viewUIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButtons];
Saurabh
2010-07-22 12:36:40
+1
A:
Mr. Ankit - Try to build your objects using through Interface builder because there is no need to maintain all the objects which are being constructed interface builder ( according to me - yet not sure - please add comment, if I am wrong anywhere ).
See,the Attached Snapshots to place Buttons on Your toolbar. Just make connections to your class IBOutlet objects.
I know - you have mentioned "Dynamic" word in your question.
You just need to add subview in to your view.
For example
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:toolBarView]; // add whenever required.
// alternate option
toolBarView.hidden=YES; // or NO whatever required.
}
sugar
2010-07-20 12:43:24