Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use a UIToolbar vs using a UIView?

I'm building an instant messenger app in iOS. In particular I'm implementing the UI for a conversation in the most typical way, that is placing an input bar at the bottom of the view (UICollectionView to be clear) that scrolls above the keyboard. Now, I'm wondering if I should implement this view as a UIToolbar with UIBarButtonItems instead of a custom UIView with UIButtons. What are the advantages of a UIToolbar?

like image 985
theMoonlitKnight Avatar asked Nov 17 '15 15:11

theMoonlitKnight


2 Answers

I don't think there is much difference other than convenience. With a UIToolbar you get the following:

  • UIBarButton items are arguably simpler to add to a tool bar and the layout is automatic, whereas it is a bit more complicated adding buttons to a view.

  • You can set hidesBottomBarWhenPushed on the view controllers to
    hide the bar when a view controller is pushed to the nav stack.

  • Looks more familiar to other apps, including Apple's own apps.

If you use a UIView with buttons you have more flexibility in the appearance but you have to do a bit more work, but other than that I can't really see much difference.

like image 164
BinaryGuy Avatar answered Oct 26 '22 08:10

BinaryGuy


UIToolbar will provide automatic placing of your buttons, saving you from pain of placing those buttons. It was designed specifically for this reason.

like image 33
Moshe Avatar answered Oct 26 '22 09:10

Moshe