Too Many Items for Nav Bar Layout in iOS - ios

I need some help figuring out how to fix the layout of a navigation bar in an iOS app. When adding navigation to 'child' views of a given screen, my approach so far has been to add buttons to the 'leftBarButtonItems' collection of the UINavigation item. As long as the number of buttons doesn't exceed 3 or 4 everything works great.
Unfortunately, I now have a screen that requires additional buttons. Everything seemed to build fine, but when I actually run the application I end up with a jumbled mess like this:
Is there a better way to layout a UI with nav and toolbar buttons like this? If putting the buttons in the nav bar is actually the correct way, what do I need to do to make the layout handle cases where the content can't fit?

I wouldn't bother with adding any extra buttons. Users expect most apps to behave in similar ways, and (while this is technically possible) it's an unusual thing to do.
Apple's HIG states:
Avoid crowding a navigation bar with too many controls. In general, a navigation bar should contain no more than the view’s current title, a back button, and one control that manages the view’s contents.
And, even if you choose to ignore Apple's HIG, this will certainly won't be good for accessibility. Your users can (and will) change the text size with Dynamic Type - so your assertion that it's OK if the "number of buttons doesn't exceed 3 or 4" will be proven false by someone.
You'd be better to add a toolbar instead, or find some other way of providing those features.

The navigation bar often has the title of the previous view on the left side. The right side contains a control, like Edit or a done button, to manage content within the active view.
Navigation bar Example
Apple documentation recommends to avoid crowding a navigation bar with too many controls.
A navigation bar should contain no more than the view's current title, a back button, and one control that manages the view's contents.
For the back button you should use the standard one. As for the text-field it should have enough room. If items in the nav bar are crowded consider separation by inserting fixed space by using UIBarButtonSystemItemFixedSpace constant value in UIBarButtonItem.
For more information visit the following link.
The way to go when you need 3 or more items is by using either nav bar or toolbars. You can combine both nav bar and toolbars. For more information use apple documentation on toolbars.

Related

How to Customize Toolbar inside a Navigation Controller

I have a noob question.
I am developing a simple app that uses a navigation controller (so, a nav bar on top, and a toolbar is shown on bottom via interface builder; I use storyboards). This nav controller shows a number of related tables (table views) on different screens.
My question is: I want to populate the toolbars for each screen. Ideally, I'd like to populate a label there that shows a little summary text about the contents of the table view currently displayed - but I understand that that may not be the purpose of those toolbars, and not be supported by the UIKit toolbar view.
But what should work (to my modest understanding) is to show buttons there - individualized for the current screen. But I couldn't for the life of me figure out how to do that (I tried in interface builder - but on each screen controlled by the navigation controller, the toolbar is shown, but can not be accessed; it is also not referenced in the outline for that screen - only the outline for the navigation controller shows a reference to a toolbar, and if I change anything in it, which is possible, it does not show up in any of the screens controlled by the navigation controller).
Hope this is clear enough. I think this is a very simple issue to do - but I am stuck; Google searches didn't help me. Maybe someone of You can point me to some keywords to look for?
Thanks a lot for considering!
Best regards,
Björn
What exactly are you trying to drag into the navigation controller bottom toolbar?
From my experience you are only allowed drag out Bar Button Item's along with Fixed and Flexible Spaces.

What approach should i use when making tab bar application

I'm started to work at new place as iOS programmer. I joined existing project and got an assignment that i don't really know how to approach.
So my problem is this: when you press a button, next window has to have a tab bar with four icons, this means four different navigation stacks. Its not that hard to make, but in main screen i have more then four icons, and if i press any one of them next window always has to have a tab bar with four static icons, like shortcuts or something.
So what should I do? Does anyone had the same situation? I want to start with a good advice to save trouble later on.
You should probably rethink the app design. Tapping an item on the tab bar shouldn't result in a different number of tab bar items, as it leads to an unstable and unpredictable UI.
While not the most efficient in terms of visible content, you could introduce a segmented control (or a similar custom view) on top right under the navigation bar (if there is one), as seen in the Facebook app (though here it is used to perform actions, not changing views).
Your root view controller should be embedded in a navigation controller. Then push a view controller which contains any number of tab bar items not TabBarController. Then you can present each view controller either push or custom.

ios7: UIButton on UINavigationBar is not selectable

I have a pretty unique problem. I have a custom nav controller (https://github.com/cwRichardKim/RKSwipeBetweenViewControllers) and I'm trying to customize it even further. The effect I'm trying to get is this:
What I have is this (ignore the search bar):
The problem that I have is that when you click on any of the tabs in my nav bar ("public" for example), the click doesn't register, and it clicks whatever is underneath instead. For example, if I click "Munchies", it will click the search bar underneath the tab. Also, even if there is nothing clickable underneath it (I've tried this with a blank UIViewController), the tabs (eg: "Munchies") are still not clickable.
I have a theory for why this is. If I raise the tabs by a few pixels, the tops of the tabs become clickable. So, I think the navigationBar has a frame within which you can interact with its objects, but if you interact with anything outside of that frame, it interacts with lower layers. I've tried expanding the nav bar height and it doesn't work (I've looked it up and it's against the rules).
Any thoughts?
Thanks!
I read your code here that is shown here:
https://github.com/cwRichardKim/RKSwipeBetweenViewControllers/blob/master/RKSwipeBetweenViewControllers.m
I'm not exactly sure whether this will work out. But this issue has occured to me in table cell as well. Perhaps you can try typing this in.
[navigationView setUserInteractionEnabled:NO];
I'm pretty sure that your approach is on the right track because as I read Apple documentations it says:
Custom views can contain buttons. Use the buttonWithType: method in UIButton
class to add buttons to your custom view in the style of the navigation bar.
Custom title views are centered on the navigation bar and may be resized
to fit.

iOS Navigation Bar VS UIToolBar

According to Apple's "Human Interface Guidelines" - Navigation bars should only have one other button (apart from the standard back button)
All this is fine, but there are several apps which have numerous buttons on the top Navigation bar, such as the Facebook app (Image)
My question / discussion arises from here. . .
1) Would apple accept the use of a UIToolBar in place of a Navigation bar (with a custom "back" button", which would act as a replacement for the Navigation Bar:
2) Is this how Facebook would have achieved their top bar?
3) IF I could use a toolbar instead of a Navigation Bar, i would have a small space at the top where the toolbar would overlap the "status bar" - how should i overcome this issue? -
- would placing a A UIView, in that position with an embedded Toolbar be the correct solution to this issue?
All your help / comments / guides are very much appreciated
You don't have to show the navigation bar, it can be hidden (see setNavigationBarHidden:animated:). You can use UIToolbar instead but there are a lot of options for customizing the navigation bar.
You can set the leftBarButtonItem, the titleView, or the rightBarButtonItem to be a custom view as specified in the UINavigationController class reference. Those properties take a UIBarButtonItem but that doesn't have to be a button. You can create a UIBarButtonItem using initWithCustomView: to create a UIBarButtonItem with any UIView. It can be a UIView that has multiple buttons as subviews or a search bar or segmented control or whatever views you need as long as they fit and don't violate the HIG. You can do that with any of the 3 custom views on the navBar.
1) Would apple accept the use of a UIToolBar in place of a Navigation
bar (with a custom "back" button", which would act as a replacement
for the Navigation Bar:
My advice, when faced with a "should I possibly violate the specification by working around it and hoping they don't mind" decision, is "no". Are you willing to spend the time to change the code to the meet the spec if they don't accept it?
2) Is this how Facebook would have achieved their top bar?
I'm not sure this is answerable.
3) IF I could use a toolbar instead of a Navigation Bar, i would have
a small space at the top where the toolbar would overlap the "status
bar" - how should i overcome this issue? - - would placing a A UIView,
in that position with an embedded Toolbar be the correct solution to
this issue?
I created an App with a Tool Bar AND a Navigation Bar. See the screen shots (Review page) here. The Tool Bar is at the top, beneath the navigation bar. At one point, I added a feature to make a tap on the navigation bar hide/show the tool bar. But since the longer displays came out, I have removed it. Most users don't really seem to mind the extra small hit at the top as long as the display provides the information they need.
Was this helpful?
1) Probably. I've not seen or heard of an example of Apple bothering to reject an app that used a toolbar rather than a navigation controller. However, you may get a reviewer having a bad day that decides to reject your app for that reason; it's really impossible to know for sure, but unlikely. I will say that I've submitted an app that looks similar to apps with a navigation controller but the top bar is custom, and it was accepted.
2) The Facebook top bar is most likely totally custom. You can see that the transparency effect is unlike the standard navigation bar's transparency, and the layout is not similar to any standard apple control.
3) Align your top bar (however you do it) with the topLayoutGuide in interface builder (or in code).

iOS UINavigationBar vs UIToolbar vs UITabBar

Let me know which one should be used in what case.
What are differences among them?
What are the advantage and disadvantage of each component?
The UINavigationBar class implements a control for navigating hierarchical content. It’s a bar, typically displayed at the top of the screen, containing buttons for navigating up and down a hierarchy. The primary properties are a left (back) button, a center title, and an optional right button.
An instance of the UIToolbar class is a control for selecting one of many buttons, called toolbar items. A toolbar momentarily highlights or does not change the appearance of an item when tapped. Use the UITabBar class if you need a radio button style control.
The UITabBar class implements a control for selecting one of two or more buttons, called items. The most common use of a tab bar is to implement a modal interface where tapping an item changes the selection.
To quote big brother:
Tabbar
If your application provides different
perspectives on the same set of data,
or different subtasks related to the
overall function of the application,
you might want to use a tab bar. A tab
bar appears at the bottom edge of the
screen.
A tab bar gives users the ability to
switch among different modes or views
in an application, and users should be
able to access these modes from
everywhere in the application
Toolbar
If your application provides a number
of actions users can take in the
current context, it might be
appropriate to provide a toolbar
However that doesn't give you a completely clear application-based decision. The best solution is to look at the iPhone inbuilt applications (Clock and iPod) along with Appstore-approved apps and stick to what is consistent, as that is what the Apple HIG guides and the appstore approval process boils down to.
You should take a look at the Mobile HIG (Human Interface Guidelines) for these questions.
As of June 2018, the Human Interface Guidelines (HIG) include the most current expectations for iOS, macOS, watchOS, and tvOS, including links to details for developers.
For iOS, the guideline summaries are:
Navigation Bars:
A navigation bar appears at the top of an app screen, below the status bar, and enables navigation through a series of hierarchical screens.
Toolbars:
A toolbar appears at the bottom of an app screen and contains buttons for performing actions relevant to the current view or content within it.
Tab Bars:
A tab bar appears at the bottom of an app screen and provides the ability to quickly switch between different sections of an app.
As far as advantages and disadvantages of each, one important aspect is whether you want the bar to appear at the top or bottom of a view. Navigation bars are supposed to appear at the top, while toolbars and tab bars are expected to appear at the bottom of the view.
Another is whether you want navigation functionality vs actions/tasks related to a view. Navigation Bars implement a button to return to the previous view in the stack, tab bars provide a more abrupt change (such as switching from an alarm view to a timer view, say), and toolbars are really intended for actions (such as sharing, say) rather than actual "navigation".
Note:
If you come here and find that any of the links are broken, just search on "Human Interface Guidelines" to find the current documentation.

Resources