navbar dissapearing in preview and simulator when setting constraints - ios

I'm currently following the udemy ios8/swift course and I'm completely stuck on the navigationbar part. I'm thinking it might have something to do with the fact that I'm on a higher version of Xcode, but can't seem to find the solution.
I have to set the constraints for the navbar on 0 on 3 sides so it will be centered and full width in both landscape and portrait mode. When I try to do this, I see a option thats not there on the course (Constrain to Margins). No matter how much I try to adjust the values, the navbar keeps disappearing or moving in the wrong direction. I tried unchecking the constrain to margins function and putting everything on 0, I tried 'resetting to suggested constraints' and lots of other options, but I can't seem to get my navbar look good in both landscape/portrait mode. So basically, what am I doing wrong or is there any other way to do this?

In addition to the three constraints you need to give the navigation bar a height.
Another solution is to add a navigation item to the view controller instead of a navigation bar. A navigation item will auto format a navigation bar at the top of the view.

I've been able to fix it by manually setting the constraints to 0 in the Attribute inspector after Ctrl-dragging to create them first. Not sure if this is the ideal way, but it solved my problem for now.

Related

Why does the UINavigationBar cut off part of my UIBuilder but not cut it off when tested?

As you can see in the image (in the UIBuilder), the UINavigationBar takes up probably 60px of space at the top, but that does NOT show up in the simulator. The image you see above it how I have to put those view in order for them to be as far from the top of the status bar as they are from the sides. How can I fix this?
As suggested by user vaibhav, this fixed the issue.
You need to click on your main view, go to attribute inspector, and un-click 'Adjust Scroll View Insets'. That is all. Thanks for the help!

TopLayoutGuide spacing set to 0 creates empty space

I am creating UI in xcode. I have added imageView which topLayoutGuide vertical spacing is set to 0. So I think that it should be positioned right under status bar. However it is positioned under navigation bar (which is not even present).
In the same storyboard I have some views that are embed in navigation controller and it is set to transculent=NO. But this view isnt even linked to them. So I dont think that this should be a problem.
Any ideas how to fix this?
Thanks in advance

UISplitView with UITabbar

I have a strange one that I can not seem to fix. I am currently working on updating my app to iOS7. This all worked in iOS6. It is an universal app and thus uses same xib files. However the iPad uses UISplitViews on some. Like I said, this all worked in iOS6 oh this all works on the iPhone too.
The problem is a grey bar at the bottom. I changed the tab bar to be opaque to move views up properly as i had some UI clipped to bottom of views and that went underneath the tab bar, sidetracked there. But if i set it back to translucent bar, it goes underneath but stretched properly. if i dont, it adds a bar. Other tabs work fine when NOT using splitview.
The UISplitviewController is added programmatically.
See attached image for better description.
This I have tried:
Added autoresize on splitview
Checked xib for subviews in the splitviews to have auto resize
Tried to force splitview to be screen bounds
Removed clips to bounds on all views
Removed autoresize subviews
Any ideas would be welcomed.
Thank you all.
UPDATE:
setting the background colour the uisplitview, it does colour the bar black. So the uisplitview is definitely stretching to it.
I subclassed UISplitViewController and added the line below to viewDidLoad and that fixed the grey line.
self.extendedLayoutIncludesOpaqueBars = YES;
I believe I have found an alternative solution for you. I have had the exact same problem, mostly because we are both doing something against Apple's Guidelines which is having a SplitViewController nested within a Tabbar controller (SplitView should be the root view). This was okay in iOS 5/6, but now in iOS 7 there are far too many side effects to achieve this.
The reason you see your view stretch completely when you set the bar to be translucent is because the bar is NOT taken into account when drawing the view. When you set translucent to false, it is then taken into account of the view and you will see that grey bar there because that's your view pretending there's a tabbar at the bottom of the screen.
And as always, a SplitViewcontroller's height cannot be changed, as it is determined by the visible window height.
I tried everything you did and then some. The real solution came from using a third-party Split View Controller.
I recommend switching over to https://github.com/mattgemmell/MGSplitViewController . This split view controller is actually one large View with container views living inside of it. Because of this, you avoid all the side effects of putting an actual split view controller within a tab bar.
If that doesn't float your boat, you could create your own solution which follows the same idea of having one UIViewController with two container views contained in it, though the people behind MGSplitViewController did a good job of that already.
This was the only way I was able to solve this issue, let me know if you find an alternative.
Instead of creating a subclass for UISplitViewController, I just added this code on my master's viewDidLoad:
self.splitViewController?.extendedLayoutIncludesOpaqueBars = true
For the controller that is the detail view of UISplitViewController you just do this:
-(UITabBarController*)tabBarController{
return nil;
}

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.

Simple Horizontal Button Bar for iOS

I have a requirement for a very simple Button Bar.
It should take up the width of the screen.
It should allow at least 3
buttons.
The buttons should be of equal width and together take up
the whole width of the bar.
Each button should be tappable, but not
have a selected state.
The bar will be overlaid on a MapView and positioned directly above a TabBar.
Tapping a button will launch a Modal ViewController.
I thought about using a UITabBar and not allowing its tabs to become selected, but the HIG is pretty clear that this is not correct usage and UIToolBar doesn't allow the button widths to be set.
This seems like a very simple requirement but I can't see an obvious solution. Is there something I'm missing? Can anyone suggest a solution?
What's wrong with just creating a simple view that draws an appropriate gradient, and then adding three buttons of the appropriate size?
If you're feeling ambitious, or if this is something that you're likely to use more than once, you could even have the view create the three buttons. Call it ThreeButtonBar or something. Give it a constant height and adjust the width to match that of its superview so that you can use it in portrait or landscape orientation.

Resources