Reputation: 1487
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.
Upvotes: 42
Views: 86497
Reputation: 83
navigationController?.additionalSafeAreaInsets.top = 25
Add this to viewDidLoad. it will definitely work. Successfully worked in Xcode 12-version
Upvotes: 1
Reputation: 189
simply add this line to your viewController
navigationController?.additionalSafeAreaInsets.top = 30
// where 30 is the extra space, add as per your need.
Upvotes: 18
Reputation: 1
[self.navigationController.navigationBar setPrefersLargeTitles:YES];
is going to Increase the Navigation bar height Programmatically
Upvotes: -4
Reputation: 2454
THIS SOLUTION NO LONGER WORKS IN Xcode 8.x.x and later!
you can also increase height without creating the custom navigation follow the following steps
Step 1 Selecte Navigation bar in Storyboard or XIB
Step 2 Copy ObjectID from Identity Inspector
Step 3 Open Storyboard/XIB as Source Code
Step 4 Find ObjectID in Source Code past ObjectID in search
Step 5 Edit height! thats all
I hope this will help you
Upvotes: 11
Reputation: 5945
Apple proposes not to resize navigationBar
itself, but remove shadow from bar and add custom view under your navigationBar
. This can work for most cases. Check Apple's samples.
Upvotes: 15
Reputation: 82766
select your ViewController --> select your Navigation Item --> Prompt --> Add space it increase the height
of **Navigation bar**
Programatically
Add this in viewWillAppear or viewDidAppear method
Objective-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
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 80.0)
iOS 11
objective 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
}
}
Upvotes: 45
Reputation: 3718
Add this in viewWillAppear method
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 viewDidAppear method
Upvotes: 8
Reputation: 9182
Please refer the apple recommended approach for extended navigation bar here,
https://developer.apple.com/library/content/samplecode/NavBar/Introduction/Intro.html
Upvotes: 12
Reputation: 516
We need to change the height of the navigation bar for each time the view show.So put the code on 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.
Upvotes: 1
Reputation: 906
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)
}
}
Upvotes: 12
Reputation: 4223
You can't change the height of the default NavigationBar
if I'm not wrong.
Although, you can create a custom NavigationBar
and add a custom height to it.
Upvotes: 0