小编典典

后退按钮图像-在Swift中它叫什么?

swift

我正在尝试使用Swift的内部后退按钮图像。我之前已经问过这个问题,并且得到了从上一个View继承过来的技术上正确的答案,但是如果我插入此代码,则可以控制当前View的后退按钮。

// Takeover Back Button
self.navigationItem.hidesBackButton = false
let newBackButton = UIBarButtonItem(title: "<", style: .Plain, target: self, action: "segueBack")
navigationItem.leftBarButtonItem = newBackButton

这给了我<,“ ABC”会给我ABC等,但是如何触发Swift来放置它的内部“后退按钮”图像。下面的代码不起作用,但我认为正确的做法是正确的。

let backImg: UIImage = UIImage(named: "BACK_BUTTON_DEFAULT_ICON")!
navigationItem.leftBarButtonItem!.setBackgroundImage(backImg, forState: .Normal, barMetrics: .Default)

有没有人知道如何做到这一点?


阅读 252

收藏
2020-07-07

共1个答案

小编典典

尝试将自定义视图添加为后退按钮,例如

var backButton = UIButton(frame: CGRectMake(0, 0, 70.0, 70.0))
var backImage = UIImage(named: "backBtn")
backButton.setImage(backImage, forState: UIControlState.Normal)
backButton.titleEdgeInsets = UIEdgeInsetsMake(10.0, 10.0, 10.0, 0.0)
backButton.setTitle("Back", forState: UIControlState.Normal)
backButton.addTarget(self, action: "buttonPressed", forControlEvents: UIControlEvents.TouchUpInside)
var backBarButton = UIBarButtonItem(customView: backButton)

var spacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
spacer.width = -15

self.navigationItem.leftBarButtonItems = [spacer,backBarButton]

在此处输入图片说明

外观与iOS后退按钮相同

2020-07-07