Currently have a button with an embedded image. I'd like to get the image name of the button so that I can create a UIImage with it for sharing when the user clicks the button.
I've tried a variety of methods including
let imagename = sender.currentImage
let image = UIImage(name: imagename)
This results in error "Missing argument for parameter 'inBundle' in call
Looking for some guidance on how to proceed. I am going to have many buttons similar to this one and would rather build a function than individual actions for each button.
Get the image name you have assigned to your UIButton:
let createdButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
createdButton.setImage(UIImage(named: "Image_Assigned"), for: .normal)
checkButtonName(yourButton: createdButton)
func checkButtonName(yourButton: UIButton) {
if yourButton.currentImage == UIImage(named: "Image_Assigned") {
print("IMAGE NAME IS Image_Assigned")
}
else {
print("IMAGE NAME IS NOT Image_Assigned")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With