实现在navigationController中添加toolbarItems工具栏
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
self.navigationController.toolbar.translucent = NO;
self.view.backgroundColor = [UIColor whiteColor];
UIBarButtonItem *item0 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"点击" style:UIBarButtonItemStylePlain target:self action:@selector(clickedB:)];
self.toolbarItems =@[item0,item,item0];
self.navigationController.toolbarHidden = NO;
}
-(void)clickedB:(UIBarButtonItem *)item{
NSLog(@"点击了底部工具栏");
}
转自:http://blog.csdn.net/mr_lp/article/details/50516575
样式 | 图片 |
UIBarButtonSystemItemDone | |
UIBarButtonSystemItemCancel | |
UIBarButtonSystemItemEdit | |
UIBarButtonSystemItemSave | |
UIBarButtonSystemItemAdd | |
UIBarButtonSystemItemFlexibleSpace | 无样式 |
UIBarButtonSystemItemFixedSpace | 无样式 |
UIBarButtonSystemItemCompose | |
UIBarButtonSystemItemReply | |
UIBarButtonSystemItemAction | |
UIBarButtonSystemItemOrganize | |
UIBarButtonSystemItemBookmarks | |
UIBarButtonSystemItemSearch | |
UIBarButtonSystemItemRefresh | |
UIBarButtonSystemItemStop | |
UIBarButtonSystemItemCamera | |
UIBarButtonSystemItemTrash | |
UIBarButtonSystemItemPlay | |
UIBarButtonSystemItemPause | |
UIBarButtonSystemItemRewind | |
UIBarButtonSystemItemFastForward | |
UIBarButtonSystemItemUndo | |
UIBarButtonSystemItemRedo | |
UIBarButtonSystemItemPageCurl |
可能有同学注意到 UIBarButtonSystemItemFlexibleSpace 和 UIBarButtonSystemItemFixedSpace 两个是无样式的.
那他们是做什么用的呢?
他们不是按钮,而是调整按钮间距用的对象.
让4个按钮等间距地分布在工具条中,在使用UIViewController的setToolbarItems:方法 追加按钮时,如下述代码一样在4个按钮之间追加IBarButtonSys
temItemFlexibleSpace对象即可。
例如下图:
首先创建方法
调用
在调用的过程中,使用 UIBarButtonSystemItemFlexibleSpace去占位,达到实现规范化的目的
实现效果:
相应的 UIBarButtonSystemItemFixedSpace则是使特定位置控件替代.