如何使多个右栏按钮项目在导航栏中垂直堆叠?

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

如何在绿色区域添加UIlabel? (它将在导航栏内)

我能够将徽标作为按钮图像添加到 rightBarButtonItem 中,但我无法google 找到一种方法将标签添加到导航栏中的这个特定位置。

看完之后我在想也许我必须创建一个包含徽标和 UILabel 的自定义视图,在该视图中垂直排列它们,然后将该视图放在 rightBarButtonItem 中?

编辑:这是此处其他答案中的一个独特问题,因为我正在寻找如何将 UILabel 添加到 "rightBarButtonItem" 区域之外的 NavigationBar 区域。使用 rightBarButtonItem 或将自定义视图设置为出现在 rightBarButtonItem 中并不能实现我想要的。我希望 UILabel 出现在右侧的 NavBar 中,与 "Today" 标题垂直对齐。

您可以按照以下代码片段进行操作:

let containerView = UIView()
...

let rightBarButton = UIBarButtonItem(customView: containerView)
navigationItem.rightBarButtonItem = rightBarButton

我最终发现在 collectionView 中使用自定义 header 是可行的方法(而不是尝试通过自定义 UIView 将 UILabel 放入 navigationBar 到 rightBarButtonItem space ).这对我有用,因为我希望标题和日期在滚动时消失。基本上这模仿了 iOS App Store 中的“今日”选项卡,我的解决方案终于实现了我所寻找的。

完成结果:

帮助我设置 collectionView header 和附加标签的 2 个帖子位于:

  1. How to add UICollectionView Header

  2. Display Section Header UICollectionReusableView