Xcode InterfaceBuilder simulated metrics for navbar with custom height - ios

I have a project where a custom height navigation bar is used across the app so it is 62px instead 44px tall. I am trying to build and layout my views using the storyboard editor (interface builder) although when using the Top Bar attribute set to Navigation Bar under the simulated metrics under the view controller options, this turns to be the default 44px one and not the custom height navbar (64px) I want.
This way all the view work area shows up on a different size and I always need to calculate what is going to exceed or not.
Is there any way that I can use both simulated metrics and a custom height navbar subclass gracefully while keeping the exact height I will have to work on the remaining space?

It is not possible to change the Simulated Metrics to custom values by Xcode.
A possibility is to design the custom navbar and copy it everywhere instead of the navigation, but then it is not simulated any longer.
Or you could make a little hack by going into
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/PrivatePlugIns/IDEInterfaceBuilderCocoaTouchIntegration.ideplugin/Contents/Resources
and open CocoaTouchConstraints.plist
In this file you can set the value of NavigationBar to the desired values. So if you want a Navigation Bar that is 60 high just set Maximum and minimum height to 60:
<key>NavigationBar</key>
<dict>
<key>MaximumSize</key>
<string>{10000, 60}</string>
<key>MinimumSize</key>
<string>{0, 60}</string>
</dict>
After saving you need to restart Xcode and you NavigationBar will have the desired height.

I'm afraid you can't really do that, if you want to have a similar behavior and a correct auto layout and constraints directly in Interface Building add a simple view for your custom navbar class with the correct metrics, (it will work just fine as the navigation bar inherits from UIView) just add the view, set the custom class, and add the constraints for both, the navigation bar and the top objects of your view.

Related

how to get the same size like navigation bar using custom view?

I need to recreate navigation bar using custom view, since it will be easier to make than inserting view to the actual navigation bar from apple.
I need to insert search bar and some buttons.
but I have problem to set the size of that custom navigation bar view, in some iOS device it seems little bit bigger than the navigation bar from apple, I set the autolayout like the picture below. constraint to leading, trailing and top to the superview and then set the aspect ration to 375:80
the custom view is the red one. the navigation bar in orangeVC is from apple using navigation controller
and here is the result, for iPhone XR, XSMax, it seems great, the size seems the same.
but for iPhone 8 it seems the custom view is slightly bigger
how to properly make custom view that has the same size like navigation bar from apple?
Where the ratio 375:80 are you getting from?
It's not correctly.
NavigationBar's height is 44 by default, and StatusBar is 44 for Notch type devices like iPhone X, XR, XS, XS Max and 20 in otherwise.
So you need to set 88 for Notch type devices and 64 for otherwise instead of ratio. Good luck!
Nothing needs to be calculated.
Navbar height should be 44.0 all the time.
But, Navbar top constraint should use Safe Area in place of superview. and add a status bar background view just to match your header color
The best approach I found so far, without having to create a navigation controller instance:
[self.navigationBar sizeThatFits:CGSizeZero].height;

start position of table view is wrong in simulator, and is not the same in storyboard

I created a tableview in storyboard, which looks good, but the start position is wrong in the simulator or device. The 'Label' should not be at the same position as the time. How could I solve it??
Simulated metrics are just that. Simulated. They're useful to set to how the view will actually display in order to help set up the look in the storyboard, but whether or not a navbar or tabbar shows up in the actual program is irrelevant to whether or not you've selected it as a simulated metric on the storyboard.
In this case, you're probably using constraints, and setting the label's y origin to be 0 pixels below the container view. When you use the simulated storyboard metrics, this puts the label just below the navbar that you're simulating on the storyboard. But in your actual project, you've done nothing to include a navbar on this scene, and your label is appearing at the top of the view controller.
You can either learn how to prevent the status bar from displaying... or you can move the label's y origin to being a 20 pixels down (the height of the status bar).
I can provide more help if you provide more details on how you're doing your layout (autolayout?), and exactly how you want it to look. But I'd start by leaving ALL of the simulated metrics on inferred and only ever explicitly change a simulated metric after you've written the code to programmatically add/remove one of the features you can change via the simulated metrics.
If you take nothing else away from this answer, please understand this: Selecting an item from a simulated metrics dropdown menu only changes how the view appears in the storyboard and doesn't change what will actually display in your app.
try this
self.edgesForExtendedLayout = UIRectEdgeNone;
hope this will help you.

How to make a UITableViewController subclass respect topLayoutGuide in iOS7?

in my app I have a simple UITableViewController that's just plain Objective-C code, no .xib or storyboard involved. It represents the contents of one tab in a tab bar.
Since iOS 7 its contents are overlapped by the status bar at the top and tab bar at the bottom.
Using only code, how can I make the table view add space at the top and bottom to align with topLayoutGuide and bottomLayoutGuide?
I know about
self.edgesForExtendedLayout=UIRectEdgeNone;
but that seems to simply shrink the table view to not intersect the tab bar and to disable the transparency of the tab bar. Instead I'd like the table view to add some padding.
Thanks!
Update:
I've also tried explicitly setting automaticallyAdjustsScrollViewInsets to YES, but that didn't help either (should be the default behavior anyway).
It seems this is not (yet) supported, at least for programmatically created UITableViewControllers without an UINavigationController that's embedding them.
I checked the position for both layout guides, and at run-time both off-sets read 0 distance from the edges of the screen. Hence automaticallyAdjustsScrollViewInsets won't set the insets correctly.
So now I actually modify my first section header and last section footer manually to add 21 pixels at the top and 50 pixels at the bottom respectively.
Bummer. :-(

Blur top bar to UIView

I made a "single view" app with a UIView interface in a .xib file. I added a navigation bar at the top with some buttons on it and all worked fine in iOS 6.
With Xcode 5 my navigation bar is too short and buttons overlapped status bar. I tried to add a "top bar" in the "Simulated Metrics" panel but once I run the app the bar does not appear (even if it appears in the .xib file during editing).
Same problem when I tried a tool bar because I need a 64 pixel (instead 44) high blur bar.
Does a simple solution to this problem exist? Thanks!
Simulated metrics, while editing a storyboard and/or xib are, are there for you to use when stubbing out your design. They will not show up at run time. Think of them as fictional representations or a prototype of what you would like to see in your design without actually having to implement it yet.
IE: You're not sure if you want a UINavigationBar in your design. You can layout your design with the UINavigationBar turned on in the simulated metrics and it'll show you what it looks like, but only in the editor not actual run time, and from there you can make your decision on whether or not to keep it or rearrange your other controls. Something like this is very handy if you create your UINavigationBar programmatically (like I do). If I simulate the UINavigationBar (even though I'll create it programmatically) then I can get a much better idea of where to layout all my other controls that I DO setup in IB.
All that being said, if you layout all your xib's and SB's in the interface builder then the simulated metrics really is worthless to you for the most part because you can obviously just drag and drop the control onto your xib.
Hope this helps!

Scaling entire iPad app to fit status bar

I've been searching SO and Google for a while now with no luck.
What I need to do, is in certain conditions, display a status bar at the top of my application.
When this bar shows, I need to shrink all the other content down so everything still fits on the screen.
I know I can use CGAffineTransformScale, however, I am not having any luck doing it globally for the entire app.
I'm sure I'm missing something obvious. Guess my lack of experience is showing.
Thanks
EDIT: The 'status' bar I'm referring to is NOT the standard iOS status bar. It is a custom status bar that appears only in certain conditions and sits at the top of the app.
I would check your autolayout settings on the first view you added to the controller - if you have them setup correctly then it should resize automatically.
If you use a UIViewController or any concrete subclass of that, its view should automatically adapt to whether or not the status bar is currently visible.
Now in case you use autoresizing masks, your UI should be fine. Same should apply if you use a UIScrollView.
Alternatively: In Interface Builder, select your view controller and on the attributes inspector turn off Layout: Wants Full Screen. Then, your layout will automatically adjust its size to make room for the navigation bar.

Resources