iOS 状态栏的操作以及滚动视图偏移问题

1、在开发过程中我们可能遇到更改状态栏的颜色、或者文字颜色等操作,下面就是状态栏的一些基本操作

当我们开发过程中,我们可能会遇到进入每一个页面状态栏的颜色、或者文字颜色都是不一样的。那我们怎么实现呢?

首先我们在info.plist文件加入下面这些

 <key>UIStatusBarHidden</key>
  <false/>
 <key>UIStatusBarStyle</key>
 <string>UIStatusBarStyleLightContent</string>
 <key>UIViewControllerBasedStatusBarAppearance</key>
  <false/>

加入完成以后,我们剩下的就是应用了


//设置字体颜色
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;//白色
}

//设置状态栏颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
    
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}
//!!!重点在viewWillAppear方法里调用下面两个方法
-(void)viewWillAppear:(BOOL)animated{
    [self preferredStatusBarStyle];
    [self setStatusBarBackgroundColor:[UIColor redColor]];
}

将这些代码完成以后,我们就能时时更改每一个页面的状态栏颜色

2、当我们在开发过程中,我们会发现视图向下移动一些坐标,下面这个方法就能得到解决

    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王 哪跑!!!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值