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];
  • 相关阅读:
    vim同时打开编辑多个文件
    OOB区之初认识
    nandflash擦除、写操作的状态判断
    NFS挂载文件系统:unable to get mount port number from server, using default
    交叉调试出错
    (转)C++中extern “C”含义深层探索
    arm汇编程序中的[|]
    nanflash编程的地址问题
    c# ListView控件的常用屬性、方法及事件
    ListBox常用屬性和常用事件
  • 原文地址:https://www.cnblogs.com/frosting/p/9483078.html
Copyright © 2011-2022 走看看