UIToolBar使用

1.在UINavigationController导航控制器中存在UIToolBar的,而且默认时被隐藏的。

  • 需要设置self.navigationController.toolbarHidden = NO;
    (建议最好在viewWillApper:设置)
  • 然后创建UIBarButtonItem,需要用到什么类型就加什么,系统自带了许多样式让你选择(还是自定义好看,符合国人的使用)
    UIBarButtonSystemItemDone - 


    UIBarButtonSystemItemCancel - 


    UIBarButtonSystemItemEdit -


    UIBarButtonSystemItemSave -


    UIBarButtonSystemItemAdd -


    UIBarButtonSystemItemFlexibleSpace - 可以让UIBarButtonItem靠右显示
    UIBarButtonSystemItemFixedSpace
    UIBarButtonSystemItemCompose - 


    UIBarButtonSystemItemReply - 


    UIBarButtonSystemItemAction -


    UIBarButtonSystemItemOrganize -


    UIBarButtonSystemItemBookmarks -


    UIBarButtonSystemItemSearch -


    UIBarButtonSystemItemRefresh -


    UIBarButtonSystemItemStop -


    UIBarButtonSystemItemCamera -


    UIBarButtonSystemItemTrash -


    UIBarButtonSystemItemPlay -


    UIBarButtonSystemItemPause -


    UIBarButtonSystemItemRewind -


    UIBarButtonSystemItemFastForward -


    UIBarButtonSystemItemUndo -


    UIBarButtonSystemItemRedo -

    UIBarButtonSystemItemPageCurl

    通过[self setToolBarItems:@[items1,items。。。]]添加到ToolBar上面

    2.在键盘上方添加自定义按钮

        UIToolbar * topView = [[UIToolbaralloc]initWithFrame:CGRectMake(0,0,[UIScreenmainScreen].bounds.size.width,30)];

        [topView setBarStyle:UIBarStyleDefault];

        

        UIBarButtonItem * btnSpace = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:selfaction:nil];

        

        UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

        btn.frame = CGRectMake(4,5,40,25);

        [btn setTitleColor:[UIColorblueColor]forState:UIControlStateNormal];

        [btn addTarget:selfaction:@selector(dismissKeyBoard)forControlEvents:UIControlEventTouchUpInside];

        [btn setTitle:@"完成"forState:UIControlStateNormal];

        UIBarButtonItem *doneBtn = [[UIBarButtonItemalloc]initWithCustomView:btn];

        NSArray * buttonsArray = [NSArrayarrayWithObjects:btnSpace,doneBtn,nil];

        [topView setItems:buttonsArray];

        [self.textFiled setInputAccessoryView:topView];//添加到键盘上方

    -(void)dismissKeyBoard

    {

        [self.viewendEditing:YES];

    }

    运行效果如图:


    3.UIBarButtonSystemItemFixedSpace的使用

    UIBarButtonSystemItemFlexibleSpace能自动调节按钮间的间距;另外,不仅可以调整按钮间的间距,将其配置到左端(传递给setToolbarItems:方法的数组的第一个元素)时,可创建靠右的工具条按钮。同时配置到左右端(数组的第一项及最后一项)时,将创建居中的工具条按钮!

    相关的文章链接: http://book.2cto.com/201209/4185.htmlhttp://www.jianshu.com/p/532d12375e9a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值