I have an UIBarButton in navigation bar, while clicking on back button (first tap) i need to display toast (like warning), on double tap i need to exit from the page in swift,
Following codes used for displaying toast, its working fine,
let toastLabel = UILabel(frame: CGRect(x: 20, y: self.view.frame.size.height-100, width: 350, height: 35))
toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
toastLabel.textColor = UIColor.white
toastLabel.textAlignment = .center;
toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
toastLabel.text = "demo"
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = 10;
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: 2.0, delay: 0.1, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: {(isCompleted) in
toastLabel.removeFromSuperview()
})
please guide me to acheive this task.
Use UIControlEventTouchDownRepeat event, and do action when
tapCount
is2
.Add an target-action on UIButton for the control event UIControlEventTouchDownRepeat, and do action only when the touch's tapCount is 2. Like below in Swift 3
And Then add selector as below