导航栏Swift的自定义后指示器图像

时间:2019-12-18 13:27:56

标签: ios swift uibarbuttonitem

我正在尝试为后退按钮设置自定义图像。我可以删除文本,但是默认的V形箭头仍然存在。如下所示;

我正在使用x代码11.3

enter image description here

我的代码是;

let chevronImage = UIImage(systemName: "arrow.left")!.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0))
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
navigationController?.navigationBar.backIndicatorImage = chevronImage
navigationController?.navigationBar.backIndicatorTransitionMaskImage = chevronImage

3 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "arrow.left"),
                                                   style: .plain,
                                                   target: nil,
                                                   action: nil)

答案 1 :(得分:0)

尝试创建自己的自定义导航栏类​​,并在viewDidLoad()函数中使用它

let backButtonBackgroundImage = UIImage(named: "ic_navbar_back")!
let barAppearance = UINavigationBar.appearance(whenContainedInInstancesOf[CustomNavBar.self])
barAppearance.backIndicatorImage = backButtonBackgroundImage
barAppearance.backIndicatorTransitionMaskImage = backButtonBackgroundImage

答案 2 :(得分:0)

尝试一下:

self.navigationController?.navigationBar.backIndicatorImage = images         self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = images self.navigationController?.navigationBar.tintColor = UIColor.clear