iOS开发之导航栏的一些小功能

1.隐藏/去掉 导航栏返回按钮中的文字
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
forBarMetrics:UIBarMetricsDefault];

2.设置statusBar颜色为白色


效果图


self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

3.给navigationBar上添加多个按钮


图例

下面贴一个leftItem的例子

  • (void)addLeftItem {
    UIView *leftBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 31)];

    UIButton *phonebutton = [UIButton buttonWithType:UIButtonTypeCustom];
    phonebutton.frame=CGRectMake(0, 5, 25, 25);
    [phonebutton setImage:[UIImage imageNamed:@"w_qianbao_kefu"] forState:UIControlStateNormal];

    UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, 40, 20)];
    leftLabel.text = @"客服";
    leftLabel.textColor = [UIColor whiteColor];
    leftLabel.font = [UIFont systemFontOfSize:15.0f];
    leftLabel.backgroundColor = [UIColor clearColor];

    [leftBarView addSubview:leftLabel];
    [leftBarView addSubview:phonebutton];
    leftBarView.backgroundColor=[UIColor clearColor];

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBarView];
    self.navigationItem.leftBarButtonItem = leftItem;
    }

原理:在item上添加一个view,然后再在view上添加按钮

4.给导航栏设置一张背景图
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar_back"] forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
去掉导航栏下方的线
[self.navigationController.navigationBar setShadowImage:[UIImage new]];



    文/带我逃跑吧(简书作者)
    原文链接:http://www.jianshu.com/p/bc8846f80d63
    著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值