Important differences between UIButton, UIBarButtonItem, and UITabBarItem in iOS (Xcode)


UINavigationBar

In Xcode, when you create a Navigation Controller or a Table View Controller (within a navigation controller) you are given the option to display a top bar and/or a bottom bar. The top bar is known as a Navigation Bar and we are allowed to drag buttons, text fields, segmented controllers and so on here. But space is limited. 

Note: There are a total of three items allowed on the top bar of the iPhone but a segmented controller allows us to add more than one option, and no matter how many segments it contains it only ever counts as one item.

When it comes to the Navigation Bar, it is important to grasp the difference between a UIButton and a UIBarButton. The former can display text and images, but the latter has all the system icons available: things like Share (or Action) buttons are available in the UIBarButton class.

Further, it must be noted that there are some unusual things to be aware of. First, a plain Navigation Item can be used as a central label. Second, although a UILabel cannot be dragged directly to a UINavigationBar, a UIView can and a UILabel can be a subview of that UIView. But note that a view cannot be placed on the UIToolbar. Third, you will be able to add the navigation bars to a Table View Controller in the Storyboard, but these will not display at runtime if the Table View Controller isn't inside a Navigation Controller.

Finally, don't worry, with a little experimentation you will soon see what is and isn't possible. The important thing is to know that these oddities exist, so that you know it is possible to find a way around most of them.

UIToolbar and UITabBar

A bottom bar can either be a UIToolbar or a UITabBar. A UIToolbar is capable of displaying things like a UITextField and UIBarButton items, but notably not a segmented controller or UIButton items. Meanwhile, a UITabBar can display only UITabBar items (these include: Bookmarks, Contacts, Download, Favourites, Featured, History, More, MostRecent, MostViewed, Recents, Search, and TopRated).

A greater range of buttons can be added to the bottom bar than the top bar, but be aware that when the keyboard is displayed this area will be covered and inaccessible to the user.

Further reading

iOS Human Interface Guidelines (Developer, Apple)

Note: In addition to a UINavigationBar, UIToolbar and UITabBar, it is also possible to add a search bar.

Endorse on Coderwall

Comments