I’m doing Angela Yu’s iOS Course and am on Module 7. This straightforward problem has been described in earlier questions. I’m having a bizarre problem altering the opacity of my buttons. The purpose is to have the opacity of the button change to 50% for 0.2 seconds when the button is pressed down. Nonetheless, once I run this code, solely the opacity of the textual content on the button adjustments.
@IBAction func keyPressed(_ sender: UIButton) {
// print("START")
sender.alpha=0.5
playSound(soundName: sender.currentTitle!)
Thread.sleep(forTimeInterval:0.2)
// print("END")
sender.alpha=1
}
Curiously, once I set the alpha of the button the storyboard GUI to 0.5, the background of the button begins at 50% opacity. On the primary click on, the opacity doesn’t change, after which the entire button (background+textual content) adjustments to opacity of 100%. On subsequent clicks, solely the textual content of the button adjustments opacity. Within the blow image, I set the opacity of the buttons to 50% within the storyboard GUI. I pressed C and E, and took the screenshot within the hole when C was pressed.
I’m confused why setting the alpha of the button to 1 adjustments appears to alter it for the entire button, however altering it to 0.5 solely adjustments the looks of the textual content.