Created
April 7, 2020 17:44
-
-
Save LeoAOliveira/ab8396177295aad9a945c92d4e6c977c to your computer and use it in GitHub Desktop.
Detecção do cursor em uma view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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