【问题标题】:Can I add two right-hand buttons to a UINavigationBar?我可以向 UINavigationBar 添加两个右侧按钮吗?
【发布时间】:2011-01-03 02:29:08
【问题描述】:

我希望能够拥有一个 UINavigationBar,其中包含一个左侧 UIBarButtonItem、两个右侧 UIBarButtonItem 和一个标题。

我已经求助于使用 UIToolBar 来模拟这一点,但工具栏看起来与 UINavigationBar 略有不同,而且它也不会倾斜 UIBarButtonSystemItems。

有没有办法用三个 UIBarButtonItem 制作一个 UINavigationBar?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uikit


    【解决方案1】:

    使用所有原生图形无法做到这一点。但是,如果您愿意在 Acorn 或 Photoshop 中弄点手,您可以在那里创建按钮图像,然后将几个按钮添加到 UIView,将其封装在 UIBarBUttonItem 中,并将其设置为 leftBarButtonItem。

    这个问题也解决了这个问题:How to add 2 buttons into the UINavigationbar on the right side without IB?

    【讨论】:

    • 呃,这就是我认为的答案可能是:)。如果没有人提出更好的建议,我会给你打勾。
    【解决方案2】:

    我发布了code to add two buttons to the right of the navigationBar。您可以设置barStyle = -1 而不是子类化UIToolbar

    【讨论】:

      【解决方案3】:

      从 iOS5 开始,这很容易实现 (https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/instm/UINavigationItem/setRightBarButtonItems:animated:):

      setRightBarButtonItems:动画:

      设置右栏按钮项目,可选择动画到新项目的过渡。 - (void)setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated

      讨论

      如果两个导​​航项具有相同的自定义左或右栏按钮项,则当导航项被按下或弹出时,这些栏按钮项在过渡期间保持静止。

      可用性 在 iOS 5.0 及更高版本中可用。 宣布于 UINavigationBar.h

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-31
        相关资源
        最近更新 更多