zoukankan      html  css  js  c++  java
  • iOS之导航栏基本设置

    1.先看下导航栏的构造

    2.在storyboard中创建导航栏

       选中View Controller (Main.storyboard中)

    3.设置导航栏(用代码)

    1 //设置背景颜色
    2     [self.navigationController.navigationBar setBackgroundColor:[UIColor orangeColor]];
    3     
    4     //更改导航栏的背景图片 或者背景颜色
    5     [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBar_BG"] forBarMetrics:UIBarMetricsDefault];
    1 //创建一个拥有图片的按钮
    2     UIImage *img = [[UIImage imageNamed:@"NavigationBar_Btn_Back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    3     UIBarButtonItem *back = [[UIBarButtonItem alloc]initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(back)];//back为自己定义的事件
    4     self.navigationItem.leftBarButtonItem = back;
    //自定义一个按钮 添加到导航栏的右边
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, 60, 35);//图片资源高度一般就是这里的高度
        [btn setBackgroundImage:[[UIImage imageNamed:@"NavigationBar_Btn"]stretchableImageWithLeftCapWidth:15/2 topCapHeight:35/21] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
        //创建UIBarButtonItem
        UIBarButtonItem *nextBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
        
        self.navigationItem.rightBarButtonItem = nextBtn;
    //中间的视图 -> 显示标题
        self.title = @"标题";
        self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
         //显示图片 按钮 UIView
        UIImageView *logo = [[UIImageView alloc]initWithFrame:CGRectMake(0, 34, 120, 19)];
        logo.image = [UIImage imageNamed: @"NavigationBar_Logo"];
        
        self.navigationItem.titleView = logo;
      //默认工具条UIToorBar是隐藏的
        self.navigationController.toolbarHidden = NO;//不让它隐藏
        
        //添加按钮 UIBarButtonItem
        //创建用于均分toolBar的barButtonItem
        UIBarButtonItem *flexible = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        
        UIBarButtonItem *copyBtn = [[UIBarButtonItem alloc]initWithTitle:@"Copy" style:UIBarButtonItemStylePlain target:nil action:nil];
        
        //将按钮添加到toolBar上
        self.toolbarItems = @[flexible,copyBtn,flexible];
  • 相关阅读:
    Linux 误卸载软件,所有命令不能用了咋办
    MySQL 全局锁和表锁
    MongoDB 基础
    MySQL 常见错误
    MySQL 锁信息和事务
    B2C电子商务平台概述及开发公司推荐
    O2O本地生活平台推荐
    OA办公系统哪个公司做的好
    集团企业OA系统选型推荐
    协同OA办公系统选型推荐
  • 原文地址:https://www.cnblogs.com/frosting/p/9483078.html
Copyright © 2011-2022 走看看