UIToolBar

本文详细介绍了如何在iOS导航控制器中自定义UIToolBar的显示状态、高度、样式、颜色及添加按钮。通过实例演示了如何设置UIToolBar为可见,调整其外观,并添加不同类型的UIBarButtonItem。
    //UIToolBar  是导航控制器默认隐藏的工具条
    //设置UIToolBar的隐藏状态
    self.navigationController.toolbarHidden = NO;
    
    //如何找到UIToolBar   self.navigationController.toolbar
    //UIToolBar高度:44
    
    //设置UIToolBar类型:barStyle
    self.navigationController.toolbar.barStyle = UIBarStyleDefault;
    //设置UIToolBar的颜色:barTintColor
    self.navigationController.toolbar.barTintColor = [UIColor redColor];
    //设置UIToolBar的图片
    [self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"toolBar.png"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];
    
    //UIBarButtonItem  文字类型
    UIBarButtonItem *wordButton = [[UIBarButtonItem alloc] initWithTitle:@"button" style:UIBarButtonItemStylePlain target:self action:@selector(barButtonClick:)];
    
    //UIBarButtonItem  图片类型
    UIBarButtonItem *imageButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"itemImage.png"] style:UIBarButtonItemStylePlain target:self action:@selector(imageButtonClick:)];
    
    //UIBarButtonItem  系统类型
    UIBarButtonItem *systemButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(systemButtonClick:)];
    
    //创建空格
    //会均分掉空白部分,空格的点击事件不会实现,无效
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(spaceClick:)];
    
    //向UIToolBar上面添加按钮   self.toolbarItems
    //需要接收数组:数组里面的元素必须是UIBarButtonItem类型
    self.toolbarItems = @[space, wordButton, space, imageButton, space, systemButton, space];

 

转载于:https://www.cnblogs.com/hyuganatsu/p/UIToolBar.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值