Skip to content

Instantly share code, notes, and snippets.

@LeoAOliveira
Created April 7, 2020 17:44
Show Gist options
  • Save LeoAOliveira/ab8396177295aad9a945c92d4e6c977c to your computer and use it in GitHub Desktop.
Save LeoAOliveira/ab8396177295aad9a945c92d4e6c977c to your computer and use it in GitHub Desktop.
Detecção do cursor em uma view
class ViewController: UIViewController {
@IBOutlet var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let hover = UIHoverGestureRecognizer(target: self, action: #selector(hovering(_:)))
button.addGestureRecognizer(hover)
}
@objc
func hovering(_ recognizer: UIHoverGestureRecognizer) {
switch recognizer.state {
case .began, .changed:
button.titleLabel?.textColor = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1)
case .ended:
button.titleLabel?.textColor = UIColor.link
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment