ios 如何增加Xcode中导航栏的高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31940352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:13:01  来源:igfitidea点击:

How to increase the height of navigation bar in Xcode?

iosobjective-ciphonexcodeswift

提问by Mayur Tolani

I'm working on a app, in which I need to keep a navigation bar. when I write any title on the bar, the time and the title kinda get very close to each other. I wanted to increase the height of the bar, so it can get some breathing room.

我正在开发一个应用程序,我需要在其中保留一个导航栏。当我在栏上写任何标题时,时间和标题会变得非常接近。我想增加酒吧的高度,这样它就可以获得一些喘息的空间。

回答by Anbu.Karthik

select your ViewController--> select your Navigation Item--> Prompt--> Add spaceit increasethe heightof **Navigation bar**

选择您的视图控制器- >选择您的导航项目- >提示符- >添加空间增加height**Navigation bar**

Check Image here : enter image description here

在这里检查图像: 在此处输入图片说明

Programatically

以编程方式

Add this in viewWillAppearor viewDidAppearmethod

viewWillAppearviewDidAppear方法中添加它

Objective-C

目标-C

[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, self.view.frame.size.width,80.0)];

Swift

迅速

self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 80.0)

Swift-3

斯威夫特-3

self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 80.0)

iOS 11

iOS 11

enter image description here

在此处输入图片说明

objective C

目标C

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

swift

迅速

for subview in (self.navigationController?.navigationBar.subviews)! {
       if NSStringFromClass(subview.classForCoder).contains("BarBackground") {
            var subViewFrame: CGRect = subview.frame
            // subViewFrame.origin.y = -20;
            subViewFrame.size.height = 100
            subview.frame = subViewFrame

        }

    }

回答by Naveen Shan

Please refer the apple recommended approach for extended navigation bar here,

请在此处参考苹果推荐的扩展导航栏方法,

https://developer.apple.com/library/content/samplecode/NavBar/Introduction/Intro.html

https://developer.apple.com/library/content/samplecode/NavBar/Introduction/Intro.html

回答by Timur Bernikovich

Apple proposesnot to resize navigationBaritself, but remove shadow from bar and add custom view under your navigationBar. This can work for most cases. Check Apple's samples.

Apple建议不要调整navigationBar自身大小,而是从栏中删除阴影并在navigationBar. 这适用于大多数情况。检查苹果的样品。

回答by Meghs Dhameliya

THIS SOLUTION NO LONGER WORKS IN Xcode 8.x.x and later!

此解决方案不再适用于 Xcode 8.xx 及更高版本!

you can also increase height without creating the custom navigation follow the following steps

您还可以在不创建自定义导航的情况下增加高度,请按照以下步骤操作

Step 1 Selecte Navigation bar in Storyboard or XIB

步骤 1 在 Storyboard 或 XIB 中选择导航栏

enter image description here

在此处输入图片说明

Step 2 Copy ObjectID from Identity Inspector

步骤 2 从 Identity Inspector 复制 ObjectID

enter image description here

在此处输入图片说明

Step 3 Open Storyboard/XIB as Source Code

步骤 3 打开 Storyboard/XIB 作为源代码

enter image description here

在此处输入图片说明

Step 4 Find ObjectID in Source Code past ObjectID in search

步骤 4 在源代码中查找 ObjectID 过去的 ObjectID 在搜索中

enter image description here

在此处输入图片说明

Step 5 Edit height! thats all

第 5 步编辑高度!就这样

enter image description here

在此处输入图片说明

I hope this will help you

我希望这能帮到您

回答by odm

Add the following extension to your project:

将以下扩展添加到您的项目中:

import UIKit

extension UINavigationBar {

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

}

回答by Abhishek Thapliyal

Add this in viewWillAppearmethod

viewWillAppear方法中添加这个

CGFloat height = 80;
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0,
self.view.frame.size.width,height)];

if it increase first and shrinks to original height then add this code in viewDidAppearmethod

如果它首先增加并缩小到原始高度,则在viewDidAppear方法中添加此代码

回答by Sandu

We need to change the height of the navigation bar for each time the view show.So put the code on viewWillAppear

每次view显示的时候都需要改变导航栏的高度,所以把代码放在viewWillAppear上

override func viewWillAppear(_ animated: Bool) {
     self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 80)
}

we can set the width as the width of the view and change the height as we wish.

我们可以将宽度设置为视图的宽度并根据需要更改高度。

回答by danialzahid94

You can't change the height of the default NavigationBarif I'm not wrong.

NavigationBar如果我没记错的话,你不能改变默认的高度。

Although, you can create a custom NavigationBarand add a custom height to it.

虽然,您可以创建自定义NavigationBar并为其添加自定义高度。

回答by George Bafaloukas

I would hide the navigation bar and implement a custom one on my own. That way you could style it exactly as you want.

我会隐藏导航栏并自己实现一个自定义的。这样你就可以完全按照你的意愿设计它。

There is a simple tutorial on how to do that: https://www.codeschool.com/blog/2014/11/11/ios-app-creating-custom-nav-bar/

有一个关于如何做到这一点的简单教程:https: //www.codeschool.com/blog/2014/11/11/ios-app-creating-custom-nav-bar/

回答by Sraavan Chevireddy

[self.navigationController.navigationBar setPrefersLargeTitles:YES];is going to Increase the Navigation bar height Programmatically

[self.navigationController.navigationBar setPrefersLargeTitles:YES];将以编程方式增加导航栏高度