iPad Toolbar UI Question - ios

I need to have an iPad app that has a consistent toolbar at the top of the screen. I need it to adjust when switch from landscape to portrait. Essentially what I need is something that acts like a UINavigationController, but allows me to have an arbitrary number of buttons like a UIToolbar. I've seen this done, but I can't figure out how to do it.
Thanks

There is no reason you can't just use a standard UIToolbar at the top of the screen, rather than the bottom. This allows you to add as many buttons as you can squeeze on, and customise their appearance.
In order that it should adjust its size when switching interface orientation, you simply need to adjust its autoresizingMask property. This is easy in Interface Builder - just turn on the horizontal arrow in the middle of the autoresizing box (this makes the width flexible), and maybe make sure that the left, right and top struts are enabled to so as to hold it in the correct position.

Related

Buttons going below screen in landscape mode

I am learning iphone app development and I am using swift. I took the lynda tutorial and I have created a very basic UI which is View Controller > View .
In the View I added a segmented control, two buttons(horizontal, facing each other), three labels, one textarea and two other buttons(horizontal, facing each other).
So I have these UIcomponents arranged vertically and I used 'Reset to suggested constraints' and made all the buttons equal width and equal height and everything is fine in potrait mode but as soon as I go to landscape mode the last two buttons disappear, if I add a constraint from bottom edges the whole UI gets messed up i.e. only one label and part of an upper button appears.
What should I do to make all the UI components visible both in potrait and landscape mode?
There are many ways to go about this. I've set up a github project to show you one way to achieve it.
Short resume of what I did manually without the help of the Interface Builder:
I've pinned the segmented control to the left, top and right of the parent view
The red button below has a vertical constraint to the segmented control and a leading constraint to the parent view. It also als a horizontal space constraint to the green button
The green button has a trailing constraint to the parent view, top aligned to the red button and widths set to equal to the red button.
This setup ensures, that the segmented control is responsible for specifying the distance to the top of the parent view and the red button specifies the width of itself and the green button (test it, by changing the value of the horizontal space constraint)
I've turned the same principle upside down. So the views in the bottom are always pinned to the bottom. But as I said, there are many ways to achieve this. You could also create 3 container views for the elements in the top, center and bottom and pin those to the top, center and bottom.
The running app looks like this:
If you would like to display your content differently in landscape mode, it is possible (and most likely preferable) to create an alternate landscape interface.
Quoting the Apple developer's page on the subject:
"To support an alternate landscape interface, you must do the following:
Implement two view controller objects. One to present a portrait-only
interface, and the other to present a landscape-only interface.
Register for the UIDeviceOrientationDidChangeNotification notification.
In your handler method, present or dismiss the alternate view controller based on the current device orientation."
For more information about this, check out this apple developer page and scroll down to "creating an alternate landscape interface".
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html

Why is my button not showing up in landscape mode?

I'm making a basic app in XCode but setting up all the components is giving me trouble, why will this button not appear in landscape mode?
The way you are using Autolayout is the problem here. You are setting constants for the distances of bottom space and top space. When the device orientation changes, this leads to undesired results, such as that the button is not on screen any more.
A better approach will be to position the views relative to each other. So, if you want the button to stay directly beneath the text field, you can set the vertical space of these two components instead of using bottom space for the button.
Its an issue of constraints.
Set the constraints relative to your above textfield.
You are setting 347px from bottom, which leads the button to get out from the screen.

Creating custom implementation of navigation bar

I wish to create a view similar in behavior to the UINavigationBar.
I cannot simply customize the bar as I want the space to be taller and I want to have several other subviews on it other than just UIBarButtonItems. So, I want to be able to create a similar implementation including the floating/translucency effect.
I good example of this is the address bar in Safari in iOS 7. The UITextField on the bar is something that cannot be added on the default UINavigationBar. Nevertheless, the Safari bar still has the transparency.
I do not want it to shrink like it does in Safari when scrolling down, I simply want it to remain just like a UINavigationBar would. I was thinking about adding a subview to the root UIScrollView, but this would scroll along with everything. I want this to remain at the top, but I want other elements to be able to scroll.
How would I go about implementing this?
If you are confident that you can't to this with the default UINavigationBar, you could shrink (from the top) the UIScrollView with whatever the size the custom UINavigationBar is and then add the navbar as a subview to the root view at (0,0) coordinates. It will be independent from the scroll view.
On the other hand, if you need this to be persistent through the application and use it in all of the screens, it will be wise to make some changes starting for the AppDelegate, but that's for another question.
For the iOS 7 transparent-style part, look here: FXBlurView. Best of luck!

UIToolbarPosition set to bottom on resize

I have a UIToolBar at the top of one of my views and the shadowing shows up on the bottom of the tool bar as I'd expect. I know UIToolbarPosition is internally set to UIToolbarPositionTop.
When I rotate my device (iPad), the tool bar grows (using auto sizing in IB) and the UIToolbarPosition changes to UIToolbarPositionBottom which flips the shadow to be at the top of the bar. If I don't have the bar resize, it remains correct, but of course doesn't stretch to match screen width.
So, what gives? What would cause the UIToolbarPosition to flip on me? This is sitting at 0,0 the whole time and only changes width based on rotation.
Extra: I've considered work arounds like using a UINavigationBar. UIAppearance is probably a no go because I do have a toolbar at the bottom too and I do want my "top" different than my "bottom"
I eventually solved this using the UIBarPositioning protocol on UIToolBarand setting the barPosition = UIBarPositionTop

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