我有UIBarButton saveBarButton
将屏幕图像保存到相机胶卷。当用户按下saveBarButton
时,图像被保存,UIBarButton saveBarButton
更改为UIImage doneIcon
1.2秒,以向用户指示图像已被保存。当saveBarButton
显示doneIcon
我禁用saveBarButton
时。但是,当我这样做时,saveBarButton
显示为灰色。
我的问题是:如何禁止UIBarButton
在禁用时变灰?
我的代码:
//create UIBarButton saveBarButton
override func viewDidLoad() {
let saveBarButton = UIBarButtonItem(image: UIImage(named: "saveIcon"), style: .Plain, target: self, action: "save:")
saveBarButton.tintColor = colorGreyDark
}
//save function called when press saveBarButton
func save(sender: UIBarButtonItem) {
//save image
deselectShape()
let window: UIWindow! = UIApplication.sharedApplication().keyWindow
let windowImage = capture(window)
UIImageWriteToSavedPhotosAlbum(windowImage
, nil, nil, nil)
//Change saveBarButton to indicate to user that image was saved
sender.image = UIImage(named: "doneIcon")
sender.enabled = false //disable saveBarButton
self.performSelector("canSaveAgain:", withObject: sender, afterDelay: 1.2)
}
//Change saveBarButton to original icon to indicate to user that can save another image
func canSaveAgain(sender: UIBarButtonItem){
sender.image = UIImage(named: "saveIcon")
sender.enabled = true //enable saveBarButton
}
答案 0 :(得分:4)
其中一种方法是使用UIBarButtonItem
创建customView
,然后使用userInteractionEnabled
代替enabled
。
let saveBarButton = UIBarButtonItem(customView: saveButton)
saveBarButton.customView?.userInteractionEnabled = false