【问题标题】:How to make a UIBarButtonItem like this如何制作这样的 UIBarButtonItem
【发布时间】:2011-06-09 08:47:31
【问题描述】:

如何制作这样的 UIBarButtonItem:

我在 SystemItem 值中找不到它。

谢谢

【问题讨论】:

    标签: objective-c cocoa-touch ios uibarbuttonitem


    【解决方案1】:

    你称之为信息按钮的图像按钮。它是一个系统按钮,

    使用下面将其作为您的 rightBarButtonItem

    UIButton* myInfoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
    [myInfoButton addTarget:self action:@selector(InfoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myInfoButton];
    

    这是UIButtonType的文档链接

    【讨论】:

    • 对,但如果你尝试这样做,你会看到你得到的是普通样式,而不是图像中显示的边框样式。
    【解决方案2】:

    这可能使用类似的东西:

    [[UIBarButtonItem alloc] initWithImage:@"info.png" style:UIBarButtonItemStyleBordered target:nil action:nil]
    

    我试过了:

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
    item.style = UIBarButtonItemStyleBordered;
    

    但似乎在自定义视图中没有应用边框样式。

    【讨论】:

      【解决方案3】:

      Swift 版本的@Jhaliya 快速复制粘贴答案:

      let infoButton = UIButton(type: .InfoLight)
      
      infoButton.addTarget(self, action: "InfoButtonClicked:", forControlEvents: .TouchUpInside)
      
      let infoBarButtonItem = UIBarButtonItem(customView: infoButton)
      
      navigationItem.rightBarButtonItem = infoBarButtonItem
      

      【讨论】:

        猜你喜欢
        • 2021-12-22
        • 2016-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-12
        • 1970-01-01
        • 2013-07-01
        • 2019-03-06
        相关资源
        最近更新 更多