• 关于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];

    }

  • 相关阅读:
    敏捷思维-架构设计中的方法学(12)Refactoring
    敏捷思维-架构设计中的方法学(11)精化和合并
    敏捷思维-架构设计中的方法学(8)架构愿景
    敏捷思维-架构设计中的方法学(10)分层 (下)
    Agile 敏捷建模思想 作者:林星
    敏捷思维-架构设计中的方法学(9)分层 (上)
    敏捷思维-架构设计中的方法学(13)稳定化
    敏捷思维-架构设计中的方法学(15)进一步阅读
    hdu 1829+hdu 1856(并查集)
    hdu 1050+hdu 1789+hdu 3177(贪心)
  • 原文地址:https://www.cnblogs.com/cnman/p/6486922.html
Copyright © 2020-2023  润新知