关于iPhone中创建自定义UIBarButton,按下时颜色不同的问题,可以通过以下方法实现:
let customButton = UIButton(type: .system)
customButton.setImage(UIImage(named: "your_image_name"), for: .normal)
customButton.setImage(UIImage(named: "your_image_name_highlighted"), for: .highlighted)
customButton.addTarget(self, action: #selector(customButtonTapped), for: .touchUpInside)
let customBarButtonItem = UIBarButtonItem(customView: customButton)
customButton.setTitleColor(UIColor.blue, for: .normal)
customButton.setTitleColor(UIColor.red, for: .highlighted)
self.navigationItem.rightBarButtonItem = customBarButtonItem
@objc func customButtonTapped() {
// 按钮点击事件的处理逻辑
}
通过以上方法,可以实现在iPhone中创建自定义UIBarButton,并在按下时改变颜色。
领取专属 10元无门槛券
手把手带您无忧上云