你好, 我在向UIBarButtonItem添加自定义操作时遇到问题 目标没有打电话 有人看到了这个问题吗? let navBarMapImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 22, height: 22)) navBarMapImageView.contentMo
我在向UIBarButtonItem添加自定义操作时遇到问题
目标没有打电话
有人看到了这个问题吗?
let navBarMapImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 22, height: 22)) navBarMapImageView.contentMode = .scaleAspectFit navBarMapImageView.image = image navBarMapImageView.isUserInteractionEnabled = true navBarMapImageView.target(forAction: #selector(openMaps), withSender: self) let navBarMapButton = UIBarButtonItem(customView: navBarMapImageView)
感谢帮助
你正在向UIImageView添加目标,它不起作用请检查下面的代码let btn1 = UIButton(type: .custom) btn1.setImage(UIImage(named: "imagename"), for: .normal) btn1.frame = CGRect(x: 0, y: 0, width: 30, height: 30) btn1.addTarget(self, action: #selector(openMaps), for: .touchUpInside) let item1 = UIBarButtonItem(customView: btn1) self.navigationItem.setRightBarButtonItems([item1], animated: true)