代码:
[items addObjectsFromArray:[NSArray arrayWithObjects:_backButton,_downloadButton,_deskPreviewButton,_lockPreviewButton,_actionButton ,nil]]; [_toolbar setItems:items];
这里我们需要用UIBarButtonItem来平衡布局,代码如下
UIBarButtonItem *flexSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease]; NSMutableArray *items = [[NSMutableArray alloc] init]; [items addObjectsFromArray:[NSArray arrayWithObjects:flexSpace,_backButton,flexSpace,_downloadButton,flexSpace,_deskPreviewButton,flexSpace,_lockPreviewButton,flexSpace,_actionButton,flexSpace ,nil]]; [_toolbar setItems:items];效果如下:
ref:http://stackoverflow.com/questions/6734170/position-a-bar-button-item-in-a-toolbar