Next 按钮类似于 IB 中导航控制器的后退按钮 - Swift 4
Next Button like the Navigation Controller's Back Button in IB - Swift 4
我确定 Interface Builder 中有预配置的 Next 按钮,看起来像 < Back 按钮,但我再也看不到它了。是否有另一种方法来显示自定义图标 AND 看起来像 Interface Builder 中的后退按钮的文本,或者这只能在代码中完成吗?
没有预配置的“下一步”按钮。
您必须创建一个栏按钮项目对象并将其设置为导航项目栏的右栏按钮项目。
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
您可以创建 UIButton object,为其设置带有标题的图像,然后使用它创建 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() {
}
我确定 Interface Builder 中有预配置的 Next 按钮,看起来像 < Back 按钮,但我再也看不到它了。是否有另一种方法来显示自定义图标 AND 看起来像 Interface Builder 中的后退按钮的文本,或者这只能在代码中完成吗?
没有预配置的“下一步”按钮。 您必须创建一个栏按钮项目对象并将其设置为导航项目栏的右栏按钮项目。
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
您可以创建 UIButton object,为其设置带有标题的图像,然后使用它创建 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() {
}