iOS 11导航栏高度自定义


72

现在在iOS 11中,该sizeThatFits方法不再从UINavigationBar子类中调用。更改框架UINavigationBar会导致故障和错误的插图。那么,有什么想法现在如何自定义导航栏高度?


1
尽管据说Beta 1中已报告的问题已解决,但Beta 2仍然存在问题:UINavigationBar子类未调用sizeThatFits。
ghr

1
在Beta 3中,sizeThatFits被调用,但似乎并没有对自定义高度做任何事情。发行说明中确实提到了此问题吗?
Alex Medearis'17年

1
对我来说,调整UINavigationBar的大小,只有视图仍然认为它是默认的44像素高度。因此,我的视图在自定义navigationBar下方绘制。ps延长的边缘在上none
Jeroen Bakker

1
是的,尽管发布说明指出,“自定义高度的导航栏”在beta 4中仍然非常小故障:“导航栏现在应该看起来正确。(32076094)”。我建议提交一份重复的错误报告。
karwag

2
UINavigationBarsizeThatFits由于动态更改带有大标题的iOS 11中导航栏的高度,因此有意不再使用它来确定其大小。因此,除了构建自己的非导航栏之外,我不知道在iOS 11中如何获得固定高度UINavigationBar。我鼓励您提出一个增强请求,要求一个API来影响iOS 11+的导航栏高度。
乔丹H

Answers:


39

根据Apple开发人员的说法(请在此处此处此处),不支持在iOS 11中更改导航栏的高度。他们在这里建议采取解决方法,例如在导航栏下方(但在其外部)查看视图,然后删除导航栏边框。结果,您将在情节提要中看到以下内容:

在此处输入图片说明

在设备上看起来像这样:

在此处输入图片说明

现在,您可以执行其他答案中建议的解决方法:创建的自定义子类UINavigationBar,向其中添加您的自定义大子视图,覆盖sizeThatFitslayoutSubviews,然后将additionalSafeAreaInsets.top导航的顶部控制器设置为customHeight - 44px,但是条形视图仍然是默认为44px,即使从视觉上看,一切看起来都很完美。setFrame正如苹果开发人员在上面的链接之一中所写的那样,我没有尝试改写,也许可行,但是:[...而且[支持]都没有更改UINavigationController所拥有的导航栏的框架(导航只要它认为合适,控制器就会很高兴地踩到您的框架变化。”

就我而言,上述解决方法使视图看起来像这样(调试视图显示边框):

在此处输入图片说明

如您所见,视觉外观非常好,可以additionalSafeAreaInsets正确按下内容,可以看到较大的导航栏,但是我在该栏中有一个自定义按钮,只有位于标准44像素导航栏下方的区域才可以单击(图像中的绿色区域)。低于标准导航栏高度的触摸无法到达我的自定义子视图,因此我需要调整导航栏本身的大小,Apple开发人员说不支持此大小。


2
要解决可点击区域的问题,请尝试将添加到您的自定义UINavigationBar的下一个重写方法code override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { return subviews.reduce(super.hitTest(point, with: event)) { (result, subview) in return result ?? subview.hitTest(convert(point, to: subview), with: event) } } 抱歉,无法 格式化
MarkII

6
Apple提供的最新项目不包括扩展的导航栏。
威志

1
@Weizhi,您可以从github下载旧版本:github.com/robovm/apple-ios-samples/tree/master/…–
Grubas

@Weizhi -他们仍然有代码包括在内,但故事板的场景辗转..
刚方

由于Apple剩下的示例尚不完整,您可以@frangulan提供一些有关如何实际实现此示例的代码吗?
Don Miguel

24

更新于2018年1月7日

该代码支持XCode 9.2,iOS 11.2

我有同样的问题。下面是我的解决方案。我假设身高为66。

如果有帮助,请选择我的答案。

创建CINavgationBar.swift

   import UIKit

@IBDesignable
class CINavigationBar: UINavigationBar {

    //set NavigationBar's height
    @IBInspectable var customHeight : CGFloat = 66

    override func sizeThatFits(_ size: CGSize) -> CGSize {

        return CGSize(width: UIScreen.main.bounds.width, height: customHeight)

    }

    override func layoutSubviews() {
        super.layoutSubviews()

        print("It called")

        self.tintColor = .black
        self.backgroundColor = .red



        for subview in self.subviews {
            var stringFromClass = NSStringFromClass(subview.classForCoder)
            if stringFromClass.contains("UIBarBackground") {

                subview.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: customHeight)

                subview.backgroundColor = .green
                subview.sizeToFit()
            }

            stringFromClass = NSStringFromClass(subview.classForCoder)

            //Can't set height of the UINavigationBarContentView
            if stringFromClass.contains("UINavigationBarContentView") {

                //Set Center Y
                let centerY = (customHeight - subview.frame.height) / 2.0
                subview.frame = CGRect(x: 0, y: centerY, width: self.frame.width, height: subview.frame.height)
                subview.backgroundColor = .yellow
                subview.sizeToFit()

            }
        }


    }


}

设置情节提要

在此处输入图片说明

设置NavigationBar类

设置自定义NavigationBar类

添加TestView

在此处输入图片说明

添加TestView +设置SafeArea

ViewController.swift

import UIKit

class ViewController: UIViewController {

    var navbar : UINavigationBar!

    @IBOutlet weak var testView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        //update NavigationBar's frame
        self.navigationController?.navigationBar.sizeToFit()
        print("NavigationBar Frame : \(String(describing: self.navigationController!.navigationBar.frame))")

    }

    //Hide Statusbar
    override var prefersStatusBarHidden: Bool {

        return true
    }

    override func viewDidAppear(_ animated: Bool) {

        super.viewDidAppear(false)

        //Important!
        if #available(iOS 11.0, *) {

            //Default NavigationBar Height is 44. Custom NavigationBar Height is 66. So We should set additionalSafeAreaInsets to 66-44 = 22
            self.additionalSafeAreaInsets.top = 22

        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

SecondViewController.swift

import UIKit

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.


        // Create BackButton
        var backButton: UIBarButtonItem!
        let backImage = imageFromText("Back", font: UIFont.systemFont(ofSize: 16), maxWidth: 1000, color:UIColor.white)
        backButton = UIBarButtonItem(image: backImage, style: UIBarButtonItemStyle.plain, target: self, action: #selector(SecondViewController.back(_:)))

        self.navigationItem.leftBarButtonItem = backButton
        self.navigationItem.leftBarButtonItem?.setBackgroundVerticalPositionAdjustment(-10, for: UIBarMetrics.default)


    }
    override var prefersStatusBarHidden: Bool {

        return true
    }
    @objc func back(_ sender: UITabBarItem){

        self.navigationController?.popViewController(animated: true)

    }


    //Helper Function : Get String CGSize
    func sizeOfAttributeString(_ str: NSAttributedString, maxWidth: CGFloat) -> CGSize {
        let size = str.boundingRect(with: CGSize(width: maxWidth, height: 1000), options:(NSStringDrawingOptions.usesLineFragmentOrigin), context:nil).size
        return size
    }


    //Helper Function : Convert String to UIImage
    func imageFromText(_ text:NSString, font:UIFont, maxWidth:CGFloat, color:UIColor) -> UIImage
    {
        let paragraph = NSMutableParagraphStyle()
        paragraph.lineBreakMode = NSLineBreakMode.byWordWrapping
        paragraph.alignment = .center // potentially this can be an input param too, but i guess in most use cases we want center align

        let attributedString = NSAttributedString(string: text as String, attributes: [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.paragraphStyle:paragraph])

        let size = sizeOfAttributeString(attributedString, maxWidth: maxWidth)
        UIGraphicsBeginImageContextWithOptions(size, false , 0.0)
        attributedString.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }




    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



}

在此处输入图片说明 在此处输入图片说明

黄色是barbackgroundView。黑色不透明度为BarContentView。

然后我删除了BarContentView的backgroundColor。

在此处输入图片说明

而已。


1
此解决方案在iOS 11.2中似乎无效,因为导航栏调用layoutSubviews()了无数次,从而冻结了应用程序。
迈克尔

1
我也面临着同样的问题@Michael
克里希纳·塔库尔

7
这些解决方法完全是骇人听闻的,可以保证在不久的将来打破!
Sumit Anantwar '18

1
在iPhone X上,导航栏的高度会发生变化,但不会再在状态栏区域下方向上扩展。是否有任何更新使其可以在iPhone X上使用?
约旦H

1
通过类名称搜索子视图非常困难。任何寻求可靠解决方案的人都应避免这种情况。
InkGolem

10

这对我有用:

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize sizeThatFit = [super sizeThatFits:size];
    if ([UIApplication sharedApplication].isStatusBarHidden) {
        if (sizeThatFit.height < 64.f) {
            sizeThatFit.height = 64.f;
        }
    }
    return sizeThatFit;
}

- (void)setFrame:(CGRect)frame {
    if ([UIApplication sharedApplication].isStatusBarHidden) {
        frame.size.height = 64;
    }
    [super setFrame:frame];
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) containsString:@"BarBackground"]) {
            CGRect subViewFrame = subview.frame;
            subViewFrame.origin.y = 0;
            subViewFrame.size.height = 64;
            [subview setFrame: subViewFrame];
        }
        if ([NSStringFromClass([subview class]) containsString:@"BarContentView"]) {
            CGRect subViewFrame = subview.frame;
            subViewFrame.origin.y = 20;
            subViewFrame.size.height = 44;
            [subview setFrame: subViewFrame];
        }
    }
}

9

补充:该问题已在iOS 11 beta 6中解决,因此下面的代码没有用^ _ ^


原始答案:

用下面的代码解决:

(我一直希望navigationBar.height + statusBar.height == 64无论statusBar的隐藏是否为真)

 @implementation P1AlwaysBigNavigationBar

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize sizeThatFit = [super sizeThatFits:size];
    if ([UIApplication sharedApplication].isStatusBarHidden) {
        if (sizeThatFit.height < 64.f) {
            sizeThatFit.height = 64.f;
        }
    }
    return sizeThatFit;
}

- (void)setFrame:(CGRect)frame {
    if ([UIApplication sharedApplication].isStatusBarHidden) {
        frame.size.height = 64;
    }
    [super setFrame:frame];
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    if (![UIApplication sharedApplication].isStatusBarHidden) {
        return;
    }

    for (UIView *subview in self.subviews) {
        NSString* subViewClassName = NSStringFromClass([subview class]);
        if ([subViewClassName containsString:@"UIBarBackground"]) {
            subview.frame = self.bounds;
        }else if ([subViewClassName containsString:@"UINavigationBarContentView"]) {
            if (subview.height < 64) {
                subview.y = 64 - subview.height;
            }else {
                subview.y = 0;
            }
        }
    }
}
@end

1
在外观中,您subview是一个UIView。以后怎么样subview.height
Pranoy C

我为UIView编写了一个帮助程序类别。
CharlieSu

iOS 11 beta 9仍然存在此问题。使用此替代方法可以解决问题。但希望他们会解决它。感谢@CharlieSu
Steffen Ruppel

1
如何将此类设置为uinavigationcontroller的导航栏?
Husein Behboodi Rad

有一个迅速的例子吗?我估计我使用子类化的UINavigationBar吗?
andromedainiative

6

使用Swift 4进行了简化。

class CustomNavigationBar : UINavigationBar {

    private let hiddenStatusBar: Bool

    // MARK: Init
    init(hiddenStatusBar: Bool = false) {
        self.hiddenStatusBar = hiddenStatusBar
        super.init(frame: .zero)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: Overrides
    override func layoutSubviews() {
        super.layoutSubviews()

        if #available(iOS 11.0, *) {
            for subview in self.subviews {
                let stringFromClass = NSStringFromClass(subview.classForCoder)
                if stringFromClass.contains("BarBackground") {
                    subview.frame = self.bounds
                } else if stringFromClass.contains("BarContentView") {
                    let statusBarHeight = self.hiddenStatusBar ? 0 : UIApplication.shared.statusBarFrame.height
                    subview.frame.origin.y = statusBarHeight
                    subview.frame.size.height = self.bounds.height - statusBarHeight
                }
            }
        }
    }
}

此代码给了我一个致命错误fatalError(“ init(coder :)尚未实现”)
piddler

4

除了覆盖之外-layoutSubviews,如果您不希望重新设置大小的导航栏隐藏您的内容,-setFrame:则应签出新添加的UIViewController的additionalSafereaInsets属性(Apple文档)。


这很重要,只需更新导航栏背景高度,即可使其与视图控制器中的内容重叠。我addionalSafeAreaInsets
无法解决的

这很重要,只需更新导航栏背景高度,即可使其与视图控制器中的内容重叠。我addionalSafeAreaInsets
无法解决的

4

尽管已在Beta 4中修复该问题,但导航栏的背景图像似乎并未随实际视图缩放(您可以通过在视图层次结构查看器中查看来验证这一点)。现在的解决方法是layoutSubviews在您的自定义中覆盖UINavigationBar,然后使用以下代码:

- (void)layoutSubviews
{
  [super layoutSubviews];

  for (UIView *subview in self.subviews) {
    if ([NSStringFromClass([subview class]) containsString:@"BarBackground"]) {
        CGRect subViewFrame = subview.frame;
        subViewFrame.origin.y = -20;
        subViewFrame.size.height = CUSTOM_FIXED_HEIGHT+20;
        [subview setFrame: subViewFrame];
    }
  }
}

如果您注意到,条形背景实际上有一个偏移量,-20使它显示在状态条的后面,因此上面的计算将其增加了。


您需要声明/实例化subviewFrame吗?或直接编辑子视图的框架?
Marco Pappalardo

1
@MarcoPappalardo固定错字,需要是局部变量
奇怪的时候

3

在Xcode 9 Beta 6上,我仍然有问题。该条始终看起来为44像素高,并被推到状态栏下方。

为了解决这个问题,我用@strangetimes代码制作了一个子类(在Swift中)

class NavigationBar: UINavigationBar {

  override func layoutSubviews() {
    super.layoutSubviews()

    for subview in self.subviews {
      var stringFromClass = NSStringFromClass(subview.classForCoder)
      print("--------- \(stringFromClass)")
      if stringFromClass.contains("BarBackground") {
        subview.frame.origin.y = -20
        subview.frame.size.height = 64
      }
    }
  }
}

我将状态栏放置在低于状态栏的位置

let newNavigationBar = NavigationBar(frame: CGRect(origin: CGPoint(x: 0,
                                                                       y: 20),
                                                         size: CGSize(width: view.frame.width,
                                                                      height: 64)
      )
    ) 

2

这就是我用的。如果您UISearchBar用作标题或其他修改条形内容大小的视图,则它适用于常规内容(44.0 px),您必须相应地更新值。使用它的风险自负,因为它有时可能会制动。

这是硬编码为90.0px高度的导航栏,可在iOS 11和更早版本上使用。您可能必须UIBarButtonItem为iOS 11之前的版本添加一些插图,以使其看起来相同。

class NavBar: UINavigationBar {

    override init(frame: CGRect) {
        super.init(frame: frame)

        if #available(iOS 11, *) {
            translatesAutoresizingMaskIntoConstraints = false
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func sizeThatFits(_ size: CGSize) -> CGSize {
        return CGSize(width: UIScreen.main.bounds.width, height: 70.0)
    }

    override func layoutSubviews() {
        super.layoutSubviews()

        guard #available(iOS 11, *) else {
            return
        }

        frame = CGRect(x: frame.origin.x, y:  0, width: frame.size.width, height: 90)

        if let parent = superview {
            parent.layoutIfNeeded()

            for view in parent.subviews {
                let stringFromClass = NSStringFromClass(view.classForCoder)
                if stringFromClass.contains("NavigationTransition") {
                    view.frame = CGRect(x: view.frame.origin.x, y: frame.size.height - 64, width: view.frame.size.width, height: parent.bounds.size.height - frame.size.height + 4)
                }
            }
        }

        for subview in self.subviews {
            var stringFromClass = NSStringFromClass(subview.classForCoder)
            if stringFromClass.contains("BarBackground") {
                subview.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: 90)
                subview.backgroundColor = .yellow
            }

            stringFromClass = NSStringFromClass(subview.classForCoder)
            if stringFromClass.contains("BarContent") {
                subview.frame = CGRect(x: subview.frame.origin.x, y: 40, width: subview.frame.width, height: subview.frame.height)

            }
        }
    }
}

然后将其添加到这样的UINavigationController子类中:

class CustomBarNavigationViewController: UINavigationController {

    init() {
        super.init(navigationBarClass: NavBar.self, toolbarClass: nil)
    }

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

    override init(rootViewController: UIViewController) {
        super.init(navigationBarClass: NavBar.self, toolbarClass: nil)

        self.viewControllers = [rootViewController]
    }

    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

我收到一个错误->致命错误:尚未实现init(coder :):
Shawn Baek

只实现初始化与编码器,如果你使用的是
果冻

谢谢回复。但是安全区的顶部没有更新。安全区域的顶部仍为44px。设置导航栏高度后如何更新安全区域的顶部。
肖恩·贝克

您可以尝试使用safeAreaInsetsUIView上的属性来更新您的安全区域。
果冻

2

这对于常规导航栏效果很好。如果您使用LargeTitle,这将无法正常工作,因为titleView的大小不会是固定的44点高度。但是对于一般观点,这应该足够了。

就像@frangulyan一样,苹果建议在navBar下面添加一个视图并隐藏细线(阴影图像)。这是我在下面提出的。我将一个uiview添加到navigationItem的titleView中,然后在该uiview中添加了一个imageView。我删除了细线(阴影图像)。我添加的uiview与navBar的颜色完全相同。我在该视图中添加了uiLabel,仅此而已。

在此处输入图片说明

这是3D图像。扩展视图位于navBar下方的usernameLabel后面。灰色,下方有一条细线。只需将您的collectionView或细细的分隔线下方锚定即可。

在此处输入图片说明

每行代码上方都说明了9个步骤:

class ExtendedNavController: UIViewController {

    fileprivate let extendedView: UIView = {
        let view = UIView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.backgroundColor = .white
        return view
    }()

    fileprivate let separatorLine: UIView = {
        let view = UIView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.backgroundColor = .gray
        return view
    }()

    fileprivate let usernameLabel: UILabel = {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.font = UIFont.systemFont(ofSize: 14)
        label.text = "username goes here"
        label.textAlignment = .center
        label.lineBreakMode = .byTruncatingTail
        label.numberOfLines = 1
        return label
    }()

    fileprivate let myTitleView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        return view
    }()

    fileprivate let profileImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.translatesAutoresizingMaskIntoConstraints = false
        imageView.clipsToBounds = true
        imageView.backgroundColor = .darkGray
        return imageView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white

        // 1. the navBar's titleView has a height of 44, set myTitleView height and width both to 44
        myTitleView.frame = CGRect(x: 0, y: 0, width: 44, height: 44)

        // 2. set myTitleView to the nav bar's titleView
        navigationItem.titleView = myTitleView

        // 3. get rid of the thin line (shadow Image) underneath the navigationBar
        navigationController?.navigationBar.setValue(true, forKey: "hidesShadow")
        navigationController?.navigationBar.layoutIfNeeded()

        // 4. set the navigationBar's tint color to the color you want
        navigationController?.navigationBar.barTintColor = UIColor(red: 249.0/255.0, green: 249.0/255.0, blue: 249.0/255.0, alpha: 1.0)

        // 5. set extendedView's background color to the same exact color as the navBar's background color
        extendedView.backgroundColor = UIColor(red: 249.0/255.0, green: 249.0/255.0, blue: 249.0/255.0, alpha: 1.0)

        // 6. set your imageView to get pinned inside the titleView
        setProfileImageViewAnchorsInsideMyTitleView()

        // 7. set the extendedView's anchors directly underneath the navigation bar
        setExtendedViewAndSeparatorLineAnchors()

        // 8. set the usernameLabel's anchors inside the extendedView
        setNameLabelAnchorsInsideTheExtendedView()
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)

        // 9. **Optional** If you want the shadow image to show on other view controllers when popping or pushing
        navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
        navigationController?.navigationBar.setValue(false, forKey: "hidesShadow")
        navigationController?.navigationBar.layoutIfNeeded()
    }

    func setExtendedViewAndSeparatorLineAnchors() {

        view.addSubview(extendedView)
        view.addSubview(separatorLine)

        extendedView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
        extendedView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        extendedView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        extendedView.heightAnchor.constraint(equalToConstant: 29.5).isActive = true

        separatorLine.topAnchor.constraint(equalTo:  extendedView.bottomAnchor).isActive = true
        separatorLine.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        separatorLine.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        separatorLine.heightAnchor.constraint(equalToConstant: 0.5).isActive = true
    }

    func setProfileImageViewAnchorsInsideMyTitleView() {

        myTitleView.addSubview(profileImageView)

        profileImageView.topAnchor.constraint(equalTo: myTitleView.topAnchor).isActive = true
        profileImageView.centerXAnchor.constraint(equalTo: myTitleView.centerXAnchor).isActive = true
        profileImageView.widthAnchor.constraint(equalToConstant: 44).isActive = true
        profileImageView.heightAnchor.constraint(equalToConstant: 44).isActive = true

        // round the profileImageView
        profileImageView.layoutIfNeeded()
        profileImageView.layer.cornerRadius = profileImageView.frame.width / 2
    }

    func setNameLabelAnchorsInsideTheExtendedView() {

        extendedView.addSubview(usernameLabel)

        usernameLabel.topAnchor.constraint(equalTo: extendedView.topAnchor).isActive = true
        usernameLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        usernameLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
    }
}

0

我将导航栏的高度加倍,以便通过子类化UINavigationBar并使用sizeThatFits覆盖高度来在默认导航控件上方添加一排状态图标。幸运的是,这具有相同的效果,并且更简单,副作用更少。我在iOS 8到11上进行了测试。将其放入您的视图控制器中:

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.navigationController) {
        self.navigationItem.prompt = @" "; // this adds empty space on top
    }
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.