1. Add flexible delimiters before and after the panel button in the toolbar element array:
toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0 , 320 , 60)]; UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshButtonAction:)]; NSArray *toolbarItems = [NSArray arrayWithObjects:flexibleSpace, barButton, flexibleSpace]; [toolBar setItems:toolbarItems animated:NO]; [self.view addSubview:toolBar];
Configuring toolbars is much easier in Interface Builder. If your view controller is inside the UINavigationController stack, you can still use IB to create the UIBarButtonItem collection collection and set self.toolbarItems to -viewDidLoad .
2. To get custom content on the toolbar, you can create a panel element with a custom view:
UIView *customView = <
source share