gpt4 book ai didi

ios - 带有自定义 UIButton 的 UIBarButtonItem 在 iOS <= 10 上不可见

转载 作者:行者123 更新时间:2023-12-01 17:28:34 25 4
gpt4 key购买 nike

我需要在我的 navigationController 左侧为我的应用程序创建一个“汉堡菜单”按钮,但由于 NavCon 是透明的,我需要在我的图标上有一个阴影。

因此,我创建了一个带有图像、阴影的自定义 UIButton,并将其添加为 UIBarButtonItem 上的自定义 View ,如下所示:

let menuButton = UIButton(type: .custom)
menuButton.addTarget(self, action: #selector(showSideMenu), for: .touchUpInside)
menuButton.setImage(#imageLiteral(resourceName: "menu_white"), for: .normal)
menuButton.tintColor = UIColor.white
menuButton.layer.masksToBounds = false
menuButton.layer.shadowColor = UIColor.black.cgColor
menuButton.layer.shadowOpacity = 1.0
menuButton.layer.shadowRadius = 5
menuButton.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)

self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: menuButton)

上面的代码在 iOS 11 上运行良好,但是当我在 ios 9 和 10(模拟器和真实设备)上测试我的应用程序时,菜单图标是不可见的。它是可点击的并且按预期工作,但没有可见的图标。

在 View Hierarchy Debugger 中,我可以看到宽度和高度为 0 的 UIButton,而在 ios 11 中,我可以看到带有嵌入式 UIButton 的普通 UIButtonBarStackview。

关于如何解决这个问题以及为什么会发生这种情况的任何想法?非常感谢你!

最佳答案

请提及按钮框架

 let menuButton =  UIButton(frame: CGRect(x: 0, y: 0, width: 70, height: 40))

可能对你有帮助 谢谢

关于ios - 带有自定义 UIButton 的 UIBarButtonItem 在 iOS <= 10 上不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51396891/

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