Hide Status Bar and Increase the height of UINavigationBar
To start off, you hide your statusBar
by following these steps:
First, put this code in viewWillAppear
:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
Second, set your info.plist
file as the below image shows:
Next, you can make a Category
of UINavigationBar
and in it set the height of the navigaionBar
.
Objective-c
in .h file
@interface UINavigationBar (Custom)
- (CGSize)sizeThatFits:(CGSize)size ;
and in .m file
@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 has wrong height because the status bar is hidden while loading
Have you try to reset the navigation and status bar as like below?
-(void)resetNavigationBar
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
}
Safe area insets change when hiding status bar iOS 11
Constraints that are set to the safe area are affected by the status bar as well as the views actual location on the screen and its transform. If you always want to just apply the top (or bottom) safe area height to your view constraint, you can do this by use of a custom constraint instead.
The following constraint will automatically set its constant
value to the height of the device's top safe area height, not affected by the status bar or other parameters. To use it, change the class of any constraint into this, and their constant
will always be the safe area height. Note that it will not change its value when the device is rotated.
Objective-C
@interface TopSafeAreaContraint : NSLayoutConstraint
@end
@implementation TopSafeAreaContraint
- (void)awakeFromNib {
[super awakeFromNib];
if (@available(iOS 11.0, *)) {
UIEdgeInsets insets = [UIApplication sharedApplication].keyWindow.safeAreaInsets;
self.constant = MAX(insets.top, 20.0);
} else {
// Pre-iOS 11.0
self.constant = 20.0;
}
}
@end
Swift
class TopSafeAreaConstraint: NSLayoutConstraint {
override func awakeFromNib() {
super.awakeFromNib()
if #available(iOS 11.0, *) {
let insets = UIApplication.shared.keyWindow?.safeAreaInsets ?? .zero
self.constant = max(insets.top, 20)
} else {
// Pre-iOS 11.0
self.constant = 20.0
}
}
}
Related Topics
How to Set the Accessibility Label for a Particular Segment of a Uisegmentedcontrol
Is Float, Double, Int an Anyobject
Refresh Only the Custom Header Views in a Uitableview
Detox: iOS Simulator How to Confirm Alert Message
Storyboard Won't Update in Simulator
Ld: Framework Not Found Stripe for Architecture X86_64
iOS Format String into Minutes and Seconds
[Nsthread Ismainthread]' Always Returns Yes
Firebase Push Notifications Custom Sound
iOS Memory Usage Increasing, Can't Find the Culprit
Swift Switch Pattern Matching with Arrays
In Swift, How to Get the Device Orientation Correctly Right After It's Launched
How to Retrieve a File/Resource in a iOS Framework Bundle from a Main Program
Carthage Build Failed Xcode 12 12A7209 Building
How to Add External Webvtt Subtitles into Http Live Stream on iOS Client