美文网首页iOS Developer
iOS开发之导航栏的一些小功能

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

作者: Ego_1973 | 来源:发表于2016-10-14 11:09 被阅读0次
    1.隐藏/去掉 导航栏返回按钮中的文字
       [[UIBarButtonItem appearance]       setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
       forBarMetrics:UIBarMetricsDefault];
    
    2.设置statusBar颜色为白色
    效果图
       self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
       [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    

    如果该方法没有用可:
    - (UIStatusBarStyle)preferredStatusBarStyle {
    return 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]];

    相关文章

      网友评论

        本文标题:iOS开发之导航栏的一些小功能

        本文链接:https://www.haomeiwen.com/subject/qemgyttx.html