How to put barbutton on UIToolbar?
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 thi开发者_C百科s task...Thanks in Advance..
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.
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.
}
alt text http://img694.imageshack.us/img694/7516/snap1i.png
精彩评论