我做了一个标签,并使用tapgesturerecogniser使其可以在水龙头上工作。但是,当我单击标签时,它不起作用,但是标签显示得很好。我将它们添加到滚动视图中。
下面是我的代码:
tryLabel.translatesAutoresizingMaskIntoConstraints = false
tryLabel.textColor = .white
tryLabel.text = "tryLabel"
tryLabel.textAlignment = .left
tryLabel.isUserInteractionEnabled = true
let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(dateAddedTapped))
tapGesture.numberOfTapsRequired = 1
tapGesture.isEnabled = true
tryLabel.gestureRecognizerShouldBegin(tapGesture)
editInfoView.addSubview(tryLabel)
tryLabel.leftAnchor.constraint(equalTo: editInfoView.leftAnchor, constant: 310).isActive = true
tryLabel.topAnchor.constraint(equalTo: editInfoView.topAnchor, constant: 150).isActive = true
tryLabel.widthAnchor.constraint(equalToConstant: 300).isActive = true
tryLabel.heightAnchor.constraint(equalToConstant: 20).isActive = true
@objc func dateAddedTapped(){print(" Date added ")}