我需要在导航控制器的左侧为我的应用程序创建一个“汉堡菜单”按钮,但是由于NavCon是透明的,我需要在我的图标上有一个阴影。
因此,我创建了一个带有图像、放置阴影的自定义uibutton,并将其添加为uibarbuttonitem上的自定义视图,如下所示:
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上测试我的应用程序(模拟器和真实设备)时,菜单图标是不可见的。它是可点击的,并按预期工作,但没有可见的图标。
在视图层次调试器中,我可以看到宽度和高度为0的uibutton,而在iOS 11中,我可以看到嵌入uibuttonBarStackView的普通uibuttonBarStackView。
有关于如何解决这个问题以及为什么会发生这种情况的想法吗?非常感谢!