zoukankan      html  css  js  c++  java
  • ios 关于自定义navigationItem,实现右侧多个按钮

    废话不多说,直接正文,有时候我们想要在导航栏实现多个Item,所以就用到了UIToolBar。

    navigationItem可以定义两个地方,rightBarButtonItem与leftBarButtonItem。

    例如,我们要实现这个导航栏样式:

    具体代码:

    UIToolbar*tools=[[UIToolbar alloc]initWithFrame:CGRectMake(5, 0, 80, 39)];
        //解决出现的那条线
        tools.clipsToBounds = YES;
    //解决tools背景颜色的问题
        [tools setBackgroundImage:[UIImage new]forToolbarPosition:UIBarPositionAny                      barMetrics:UIBarMetricsDefault];
        [tools setShadowImage:[UIImage new]
                  forToolbarPosition:UIToolbarPositionAny];
    //添加两个button
    NSMutableArray*buttons=[[NSMutableArray alloc]initWithCapacity:2];
    UIBarButtonItem*button3=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"你的图片"] style: UIBarButtonItemStyleDone target:self action:@selector(press2)];
        UIBarButtonItem*button2=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"你的图片"] style: UIBarButtonItemStyleDone target:self action:@selector(press)];
     button3.tintColor=[UIColor whiteColor];
        button2.tintColor=[UIColor whiteColor];
    [buttons addObject:button3];
        [buttons addObject:button2];
        [tools setItems:buttons animated:NO];
        UIBarButtonItem*btn=[[UIBarButtonItem    alloc]initWithCustomView:tools];
        self.navigationItem.rightBarButtonItem=btn;
    YES or NO
  • 相关阅读:
    BZOJ 3144 [Hnoi2013]切糕
    一场比赛:20170707
    BZOJ 2815 [ZJOI2012]灾难
    BZOJ 1088 [SCOI2005]扫雷Mine
    BZOJ 1052 [HAOI2007]覆盖问题
    BZOJ 3505 [Cqoi2014]数三角形
    BZOJ 2957 楼房重建
    BZOJ 2654 tree
    丁酉年六月十一ACM模拟赛
    BZOJ 3438 小M的作物 & BZOJ 1877 [SDOI2009]晨跑
  • 原文地址:https://www.cnblogs.com/oldk/p/5207029.html
Copyright © 2011-2022 走看看