UINavigationBar frame height returns 44.0 but is actually 64.0
I have a UINavigationController in a storyboard which is not using AutoLayout. With the status bar visible the actual height of the UINavigationBar is 64.0 and yet when I log
self.navigationBar.frame.size.height I get 44.0. How do I get the actual height of the UINavigationBar?
I’m using Xcode 7.3 and the storyboard builds for iOS 6.
3 Solutions Collect From Internet About “UINavigationBar frame height returns 44.0 but is actually 64.0”
The height of the
UINavigationBar is 44. The reason you´re getting 64 is because of your status bar is visible and it has a height of 20.
To calculate the height you could:
let height = Double(UIApplication.shared.statusBarFrame.height) + Double(self.navigationController!.navigationBar.frame.height)
Do not use magic numbers. Use the view controller’s
topLayoutGuide.length to get the correct height. Navigation bar height and status bar height can change during runtime, so run your code in
viewDidLayoutSubviews to always use the correct value.
The cleanest way is to just care of the navigationBar position and height and not assume there is a status bar over it. (As a matter of fact if the phone orientation is landscape there won’t even be a status bar.
Just do this:
let height = Double(self.navigationController!.navigationBar.origin.y) + Double(self.navigationController!.navigationBar.frame.height)
- What's wrong with this observeValueForKeyPath:ofObject:change:context: implementation?
- How to change the color of UIPickerView Selector
- Filtering NSArray of NSDictionary objects using NSPredicate
- Get row index of custom cell in UITableview
- How to lose margin/padding in UITextView?
- Retrieve info.plist file from command-line tool
- NSFetchedResultsController: Multiple FRCs, Delegate Error when Updating
- Unable to parse JSON from AFNetworking's responseObject
- UIBarButtonItem changing title not working
- Interface Builder change text color bug?
- WatchOS App 4.0: How to schedule a local notification
- iPhone – finalizing Apple's vague “VerificationController.m”
- UITableViewCell Set selected initially
- Creating an Objective-C equivalent Getter and Setter in Swift
- Can you use string/character literals within Swift string interpolation?