zoukankan      html  css  js  c++  java
  • iOS设置UINavigationBar 的样式

    为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar

    	
    UINavigationBar *bar = self.navigationController.navigationBar;
    
    1
     

    [bar setTintColor:[UIColor whiteColor]];
    

    设置导航栏Title颜色

    1
    2
    3
    [
    bar setTitleTextAttributes:@{
                                      NSForegroundColorAttributeName :[UIColor whiteColor]
                                      }];
    
    如果需要设置返回按钮的颜色,设置bar的tintColor即可


    设置UINavigationBar背景图片

    1
    [bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsDefault];
    1
     


    设置UINavigationBar全透明, 此处随便设置一张图片即可,重要的是BarMetrics属性决定了bar的样式

    1
    [bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsCompact];
    1
     


    设置导航栏下方不显示内容,此时导航栏无透明度

    1
    self.extendedLayoutIncludesOpaqueBars = YES;
    1
     
    使用storyBoard需要在控制器中设置

     



    完成之后就是这样了,但是bar的tintColor会成为下方内容的颜色。 

    同时在滚动视图中 设置

    automaticallyAdjustsScrollViewInsets属性可以控制滚动内容是否会在bar下方显示。

     
  • 相关阅读:
    bzoj 1367
    codeforces 757F
    bzoj 3600
    比赛环境设置
    线段树合并
    BZOJ2105: 增强型LCP
    BZOJ3156: 防御准备
    BZOJ3252: 攻略
    BZOJ2464: 中山市选[2009]小明的游戏
    Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水
  • 原文地址:https://www.cnblogs.com/code-changeworld/p/4663656.html
Copyright © 2011-2022 走看看