zoukankan      html  css  js  c++  java
  • NavigationController导航栏中添加多个UIBarButtonItem

    LINK ADDRESS:http://linglong117.blog.163.com/blog/static/27714547201011191020643/

    在实际的开发中,导航器是最重要的容器之一,我们经常要在导航栏中添加各种样式的按钮,添加一个按钮很简单,代码如下图:

    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Setting" style:UITabBarSystemItemContacts 
                                                                     target:self action:@selector(clickSettings:)];          
    self.navigationItem.rightBarButtonItem = anotherButton; 
    [anotherButton release];

    其中按钮的样式可以有多种,具体的可以参考:https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html

    在有些项目中要在右面添加两个按钮,实现的样式如下图:

    image

     

    实现的代码如下图:

    UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)]; 
    [tools setTintColor:[self.navigationController.navigationBar tintColor]]; 
    [tools setAlpha:[self.navigationController.navigationBar alpha]]; 
    NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];

    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                            target:self action:@selector(clickSettings:)];

    UIBarButtonItem *anotherButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UITabBarSystemItemContacts
                                                            target:self action:@selector(clickEdit:)]; 
    [buttons addObject:anotherButton]; 
    [anotherButton release]; 
    [buttons addObject:anotherButton1]; 
    [anotherButton1 release]; 
    [tools setItems:buttons animated:NO]; 
    [buttons release]; 
    UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
    self.navigationItem.rightBarButtonItem = myBtn;

    [myBtn release]; 
    [tools release];

  • 相关阅读:
    简单工厂
    Java鲁棒性(健壮性)
    外部类,成员内部类,局部内部类能被哪些修饰符修饰
    Java枚举类的7种常用的方法
    同步,异步,阻塞,非阻塞
    对于面向对象的基本理解
    对于数组的一点理解
    类加载机制-双亲委派机制(三)
    架构- 数据库的优化
    python调用jenkinsapi
  • 原文地址:https://www.cnblogs.com/xingchen/p/2097838.html
Copyright © 2011-2022 走看看