I am trying to make a button inactive until buttons have been pressed and their background image has been changed. I started to use the same code from a similar question in regards to textfields. I am getting a lot of errors as I expected since I don't know what to change certain code to but here it is:
override func viewDidLoad() {
super.viewDidLoad()
requestPaymentButton.layer.cornerRadius = 20
requestPaymentButton.isEnabled = false
[story1Button, story2Button].forEach({ $0.addTarget(self, action: #selector(imageChanged), for: .editingChanged) })
}
@objc func imageChanged(_ button: UIButton) {
if button.currentBackgroundImage == nil {
if button.currentBackgroundImage == {
textField.text = ""
return
}
}
guard
let story1 = story1Button.currentBackgroundImage, // (story1 has no background image),
let story2 = story2Button.currentBackgroundImage, (//story2 has no background image)
else {
requestPaymentButton.isEnabled = false
return
}
requestPaymentButton.isEnabled = true
}
I have code that changes each of the buttons and removes their initial image so it just shows the image. I want the button to become active after each of these button has their background image changed. Any help would be awesome.
EDIT:
Here is the code for how the images are getting picked:
internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey(rawValue: "UIImagePickerControllerOriginalImage")] as? UIImage
{
if flag == 1
{
story1Button.setBackgroundImage(image, for: .normal)
story1Button.setImage(UIImage.init(named: "Default"), for: .normal)
}
else if flag == 2
{
story2Button.setBackgroundImage(image, for: .normal)
story2Button.setImage(UIImage.init(named: "Default"), for: .normal)
}
else if flag == 3
{
story3Button.setBackgroundImage(image, for: .normal)
story3Button.setImage(UIImage.init(named: "Default"), for: .normal)
}
else if flag == 4
{
analytics1Button.setBackgroundImage(image, for: .normal)
analytics1Button.setImage(UIImage.init(named: "Default"), for: .normal)
}
else if flag == 5
{
analytics2Button.setBackgroundImage(image, for: .normal)
analytics2Button.setImage(UIImage.init(named: "Default"), for: .normal)
}
else if flag == 6
{
analytics3Button.setBackgroundImage(image, for: .normal)
analytics3Button.setImage(UIImage.init(named: "Default"), for: .normal)
}
}
self.dismiss(animated: true, completion: nil)
}