gpt4 book ai didi

ios - 自定义导航栏后退按钮标题

转载 作者:行者123 更新时间:2023-11-29 05:29:32 26 4
gpt4 key购买 nike

我想要带有操作的自定义导航栏后退按钮标题。

我的图片:

enter image description here

我需要这样的后退按钮。这里我成功添加了文本,但没有返回箭头。这里我的代码有后退按钮的操作。

这是我的代码

    //Custom barButtonItem with custom alert function
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "< Dialer", style: .plain, target: self, action: #selector(back(sender:)))
self.navigationItem.leftBarButtonItem = newBackButton

当我添加上面的代码时,它变得像这样。 enter image description here

最佳答案

func backButtonConfiguration(_ title : String, backImageName : String) {
let backImage : UIImage = UIImage(named: backImageName)!
self.navigationBar.backIndicatorImage = backImage.withRenderingMode(.alwaysTemplate)
self.navigationBar.backIndicatorTransitionMaskImage = backImage
self.navigationBar.backItem?.title = title
}

更新

如果我们需要后退按钮的自定义操作,那么我们必须添加自定义 BarButtonItem。如果我们需要栏后退按钮看起来与内置后退按钮相同,那么我们可以创建自定义 View 并将其用作栏按钮项目

  weak var customView : UIView!

lazy var leftBarButtonView : UIBarButtonItem! = {
let btnBack = UIBarButtonItem(customView: customView)
let gesture = UITapGestureRecognizer(target: self, action: #selector(btnButtonClicked(_:)))
gesture.numberOfTapsRequired = 1
self.customView.addGestureRecognizer(gesture)
self.customView.isUserInteractionEnabled = true
return btnBack
}()

@objc func btnButtonClicked(_ gesture : UITapGestureRecognizer) {
self.navigationController?.popViewController(animated: true)
}

self.navigationItem.leftBarButtonItems = [leftBarButtonView]

关于ios - 自定义导航栏后退按钮标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com