隐藏状态栏并增加UINavigationBar的高度 [英] Hide Status Bar and Increase the height of UINavigationBar

查看:105
本文介绍了隐藏状态栏并增加UINavigationBar的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用故事板创建导航栏。

I am using story board to create navigation bar.

我的要求是隐藏状态栏并增加导航栏的高度。当我隐藏状态栏时,导航栏会粘到顶部,高度为44像素。我需要导航栏高度为64像素(44像素+状态栏高度)。有没有办法做到这一点?

My requirement is to hide the status bar and increase the height of Navigation bar. When i hide the status bar, the navigation bar sticks to top and the height is 44 px. i need a navigation bar height as 64 px (44px+status bar height). Is there any way to do this?

状态栏


没有状态栏

推荐答案

首先,按照以下步骤隐藏 statusBar

To start off, you hide your statusBar by following these steps:

首先,将此代码放入 viewWillAppear

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

其次,设置 info.plist 文件如下图所示:

Second, set your info.plist file as the below image shows:

接下来,您可以制作一个类别 UINavigationBar 并在其中设置 navigaionBar 的高度。

Next, you can make a Category of UINavigationBar and in it set the height of the navigaionBar.

Objective-c

在.h文件中

@interface UINavigationBar (Custom)
- (CGSize)sizeThatFits:(CGSize)size ;

和.m文件

@implementation UINavigationBar (Custom)

- (CGSize)sizeThatFits:(CGSize)size {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGSize newSize = CGSizeMake(width, 100);
    return newSize;
}

Swift

extension UINavigationBar {
    public override func sizeThatFits(size: CGSize) -> CGSize {
        let width = UIScreen.mainScreen().bounds.width
        let newSize = CGSize(width: width, height: 64)
        return newSize
    }
}

这篇关于隐藏状态栏并增加UINavigationBar的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆