ios 导航栏状态栏设置

来源:互联网 发布:超级马里奥知乎 编辑:程序博客网 时间:2024/05/17 09:04

导航栏的一些设置

1.1 导航栏渐变效果

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{    CGFloat offset = self.tableView.contentOffset.y;    CGFloat delta = -offset / 64.f + 1.f;    delta = MAX(0, delta);    [self navigationController].navigationBar.alpha = MIN(1, delta);}

1.2 导航栏全透明

iOS7之后由于navigationBar.translucent默认是YES,坐标零点默认在(0,0)点 当不透明的时候,零点坐标在(0,64);如果你想设置成透明的,而且还要零点从(0,64)开始,那就添加:self.edgesForExtendedLayout = UIRectEdgeNone;

- (void)viewDidLoad {    [superviewDidLoad];    [self setMyBavBar];   }-(void)setMyBavBar{       // 透明导航栏        self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];        //    导航栏变为透明        [self.navigationController.navigationBarsetBackgroundImage:[UIImagenew] forBarMetrics:0];        //    让黑线消失的方法        self.navigationController.navigationBar.shadowImage = [UIImage new];}

把导航栏设置成 透明色是一种办法, 还有一种办法是把navigationBar隐藏.

self.navigationController.navigationBarHidden = YES;

二. 状态栏设置

2.1 状态栏的显示与隐藏

  1. 在启动图中隐藏. 启动后显示,
    target 中勾选隐藏,

    在appdelegate中
    [application setStatusBarHidden:no]

  2. 一直都显示
    在infoplist中设置

    View controller-based status bar appearance : no

    在appdelegate

    [application setStatusBarHidden:YES];

2.2 跟换状态栏的颜色

参考链接 http://www.jianshu.com/p/5c09c2700038
* 默认的黑色(UIStatusBarStyleDefault)
* 白色(UIStatusBarStyleLightContent)

全局设置状态栏的状态

[UIApplicationsharedApplication].statusBarStyle=UIStatusBarStyleDefault;

根据不同场景调整状态栏

-(void)viewWillAppear:(BOOL)animated{       [self setStatusBarBackgroundColor:[UIColor redColor]];       [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;  } - (void)setStatusBarBackgroundColor:(UIColor *)color {      UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];      if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {          statusBar.backgroundColor = color;      }  }  
原创粉丝点击