【问题标题】:Next Button like the Navigation Controller's Back Button in IB - Swift 4 [closed]下一个按钮,如 IB 中导航控制器的后退按钮 - Swift 4 [关闭]
【发布时间】:2018-03-30 13:26:17
【问题描述】:

我确定 Interface Builder 中有预配置的 Next 按钮,看起来像 按钮,但我没有看到它了。是否有另一种方法可以显示自定义图标 AND 文本,看起来像 Interface Builder 中的后退按钮,或者只能在代码中完成?

【问题讨论】:

    标签: ios swift interface-builder uinavigationbar


    【解决方案1】:

    您可以创建 UIButton 对象,为其设置带有标题的图像,然后使用它创建您的 UIBarButtonItem:

        let button = UIButton(type: .System)
        button.setImage(UIImage(named: "YourImage"), forState: .Normal)
        button.setTitle("YourTitle", forState: .Normal)
        button.sizeToFit()
        self.leftBarButton = UIBarButtonItem(customView: button)
    

    添加动作:

        button.addTarget(self, action: #selector(self.tappedAction), forControlEvents: .TouchUpInside)
    

    self.someAction 在哪里

    func tappedAction() {
    
    }
    

    【讨论】:

      【解决方案2】:

      没有预配置的下一步按钮。 您必须创建一个条形按钮项对象并将其设置为导航项栏的右条形按钮项。

      let homeButton : UIBarButtonItem = UIBarButtonItem(title: "LeftButtonTitle", style: UIBarButtonItemStyle.Plain, target: self, action: "")
      
      let logButton : UIBarButtonItem = UIBarButtonItem(title: "RigthButtonTitle", style: UIBarButtonItemStyle.Plain, target: self, action: "")
      
      self.navigationItem.leftBarButtonItem = homeButton
      self.navigationItem.rightBarButtonItem = logButton
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多