Im having problems receiving a UITapGesture
on a UILabel
which is a subview of a UIPickerView
.
let statusDisplayLabel = UILabel(frame: CGRect(x: 0,
y: 0,
width: <#width of UIPickerView #>,
height: <# height of UIPickerView row #>))
statusDisplayLabel.isUserInteractionEnabled = true
let tapGesture = UITapGestureRecognizer(target: self,
action: #selector(didTapStatusDisplayLabel(tap:)))
tapGesture.numberOfTapsRequired = 1
tapGesture.numberOfTouchesRequired = 1
statusDisplayLabel.addGestureRecognizer(tapGesture)
<# UIPickerView #>.addSubview(statusDisplayLabel)
@objc func didTapStatusDisplayLabel(tap: UITapGestureRecognizer){
print("tapped")
}
The UILabel
displays as it should over the UIPickerView
. However "tapped" message is never displayed in console as the tap just falls through the statusDisplayLabel
and moves the UIPickerView
instead. It's as if the UILabel
is not there
What am I missing?
Try to create Container View, put into this view your UIPickerView and try to add label not into the picker view, but inside the Container View.