Search code examples
iosswiftxcodeuinavigationbaruibarbuttonitem

How to make multiple right bar button items stack vertically in navigation bar?


How can I add a UIlabel to the area in green? (it will be within the navigation bar)

enter image description here

I was able to add the logo as a button image in rightBarButtonItem, but I can't google a way to add a label to the nav bar in this specific position.

After reading around I'm thinking maybe I have to create a custom view that would contain the logo and a UILabel, arrange them vertically within that view, and then place that view in rightBarButtonItem?

edit: This is a unique problem from other answers here in that I am looking for how to add a UILabel to an area of the NavigationBar that is outside of the "rightBarButtonItem" area. Using rightBarButtonItem or setting a custom view to appear within rightBarButtonItem does not achieve what I am looking for. I want a UILabel to appear in the NavBar on the right side aligned vertically with the "Today" title.


Solution

  • I ended up figuring out that using a custom header within the collectionView is the way to go (rather than trying to place a UILabel into the navigationBar via a custom UIView into the rightBarButtonItem space). This worked for me because I wanted the title and date to disappear upon scrolling anyway. Basically this mimics the "Today" tab in the iOS App Store, and my solution finally achieved what I was looking for.

    Finished result:

    The 2 posts that helped me set up the collectionView header and attach the labels are here:

    1. How to add UICollectionView Header

    2. Display Section Header UICollectionReusableView