Reputation: 4166
I have a UIBarButton saveBarButton
to save an image of the screen to the camera roll. When the user presses the saveBarButton
the image is saved and the UIBarButton saveBarButton
changes to the UIImage doneIcon
for 1.2 seconds to indicate to the user that the image has been saved. When the saveBarButton
displays the doneIcon
I disable saveBarButton
. However, when I do that the saveBarButton
is greyed out.
My question is: how do I stop the UIBarButton
from greying out when disabled?
My code:
//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
}
To see what I'm talking about.
Upvotes: 3
Views: 755
Reputation: 10215
One of ways is to create UIBarButtonItem
with customView
and use userInteractionEnabled
instead enabled
.
let saveBarButton = UIBarButtonItem(customView: saveButton)
saveBarButton.customView?.userInteractionEnabled = false
Upvotes: 5