zoukankan      html  css  js  c++  java
  • 关于NavigationBar的笔记

    1常用几个方法 全局

    //设置navigationBar 的类型 ,ps:

    status bar的状态受navigationbar控制(当用navigationcontroller时,通过设置此属性改变状态栏的状态)

     
        self.navigationBar.barStyle = UIBarStyleDefault;
    

    //status bar的状态受navigationbar控制

       self.navigationBar.barStyle = UIBarStyleDefault;

    //设置背景

       [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

    //设置背景图片

    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"] forBarPosition:UIBarPositionTop barMetrics:UIBarMetricsDefault];

    //设置背景透明

     [self.navigationBar setTranslucent:true] ;

      [self.navigationBar setBackgroundImage:[UIImage  new] forBarPosition:UIBarPositionTop barMetrics:UIBarMetricsDefault];

    //返回item或其他item的图片或文字颜色

        [[UINavigationBar appearance] setTintColor:[UIColor redColor]];

    //设置标题的属性

        //标题文字属性
        NSShadow *shadow = [[NSShadow alloc]init];
        shadow.shadowBlurRadius = 5;//模糊度
        shadow.shadowColor = [UIColor whiteColor];//阴影颜色
        shadow.shadowOffset = CGSizeMake(1, 5);//阴影的大小
        
        [self.navigationBar setTitleTextAttributes:@{
            NSFontAttributeName:[UIFont systemFontOfSize:22],
            NSForegroundColorAttributeName:[UIColor greenColor],
            NSShadowAttributeName:shadow
                                                     }];
    

     //隐藏某个控制器的导航返回按钮

    [self.navigationItem setHidesBackButton:true];

      //改变返回的文字的位置(消失)

        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) forBarMetrics:UIBarMetricsDefault];

        //设置返回按钮显示的图片(以下两个属性需同时设置)

        [self.navigationBar setBackIndicatorImage:[UIImage new]];

        [self.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];

    2 单独设置某个页面的返回按钮的时候

      假设A--->push-->B  要设置B的返回键文字为‘b的返回’

      那么要在A控制器中设置

         self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"b的返回" style:UIBarButtonItemStylePlain target:self action:@selector(pop)]

    3 note!!!

    若出现下面的需求:及当前的控制器隐藏掉导航栏设置annimated属性为No的话会出现不可预料的bug,最好这里animated:yes 或者和视图的一样!

    - (void)viewWillAppear:(BOOL)animated{

        [super viewWillAppear:animated];

        [self.navigationController setNavigationBarHidden:YES animated:animated];

       }

    - (void)viewWillDisappear:(BOOL)animated{

        [super viewWillDisappear:animated];

        [self.navigationController setNavigationBarHidden:NO animated:animated];

    }

  • 相关阅读:
    mysql导入导出sql文件
    linux 监控文件变化
    LeetCode:595.大的国家
    LeetCode:176.第二高的薪水
    LeetCode:182.查找重复的电子邮箱
    Excel学习笔记:行列转换
    通过数据分析题目实操窗口函数
    Oracle学习笔记:窗口函数
    Python学习笔记:利用爬虫自动保存图片
    电商数据分析基础指标体系(8类)
  • 原文地址:https://www.cnblogs.com/cnman/p/6486922.html
Copyright © 2011-2022 走看看