Answers for "change opacity of button clicked swift"

6

change opacity of button clicked swift

@IBAction func keyPressed(_ sender: UIButton) {
  // sets opacity to half - you can change the opacity by editing "0.5"
  sender.alpha = 0.5
  
  /* 
  Code should execute after 0.2 second delay.
  You can change delay by editing 0.2.
  */
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
    // Bring's sender's opacity back up to fully opaque
    sender.alpha = 1.0
  }
  
 }
Posted by: Guest on June-15-2020
0

change opacity of button clicked swift

@IBAction func keyPressed(_ sender: UIButton) {
  playSound(soundName: sender.currentTitle!)

  //Reduces the sender's (the button that got pressed) opacity to half.
  sender.alpha = 0.5

  //Code should execute after 0.2 second delay.
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
      //Bring's sender's opacity back up to fully opaque.
      sender.alpha = 1.0
  }
}

func playSound(soundName: String) {
    let url = Bundle.main.url(forResource: soundName, withExtension: "wav")
    player = try! AVAudioPlayer(contentsOf: url!)
    player.play()
}
Posted by: Guest on August-16-2021

Code answers related to "change opacity of button clicked swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language