IOS 设置UIToolbar的UIBarButtonItem的间距

============================================================
博文原创,转载请声明出处
电子咖啡-专注于移动互联网
============================================================
我用代码添加了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

你可能感兴趣的:(IOS*mac)