============================================================博文原創,轉載請聲明出處電子咖啡-專註於移動互連網============================================================
我用代碼添加了UIBarButtonItem,但是結果如下:
代碼:
[items addObjectsFromArray:[NSArray arrayWithObjects:_backButton,_downloadButton,_deskPreviewButton,_lockPreviewButton,_actionButton ,nil]]; [_toolbar setItems:items];
太醜了不是,我需要將UIBarButtonItem均勻分布到tabbar上。
這裡我們需要用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