navigationController中添加toolbarItems工具栏____UIBarButtonSystemItem的样式解析

31 篇文章 0 订阅
15 篇文章 0 订阅


实现在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

UIBarButtonSystemItem的样式解析
样式图片
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对象即可。

例如下图:


首先创建方法

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. -  (UIBarButtonItem*)barButtonSystemItem :(UIBarButtonSystemItem) systemItem {  
  2.       
  3.     UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:nil action:nil];  
  4.       
  5.     return button;  
  6.       
  7. }  

调用

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [self setToolbarItems:[NSArray arrayWithObjects:[self barButtonSystemItem:UIBarButtonSystemItemAction],  
  2.                        [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],  
  3.                        [self barButtonSystemItem:UIBarButtonSystemItemBookmarks],  
  4.                        [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],  
  5.                        [self barButtonSystemItem:UIBarButtonSystemItemCancel],  
  6.                        [self barButtonSystemItem:UIBarButtonSystemItemFlexibleSpace],  
  7.                        [self barButtonSystemItem:UIBarButtonSystemItemEdit],nil]];  


在调用的过程中,使用  UIBarButtonSystemItemFlexibleSpace去占位,达到实现规范化的目的

实现效果:



相应的 UIBarButtonSystemItemFixedSpace则是使特定位置控件替代.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值