Ron*_*nit -2 uilabel ios uitapgesturerecognizer swift3
我在UIView中添加了Label并创建了它的插座,然后在UITapGestureRecognizer的帮助下我添加了功能,但是当我点击或点击标签时.标签文本不会更改.我搜索了类似的问题,我得到的答案也是我写的,但标签文字仍未改变.用Swift 3.0编写的代码.这是我写的代码 -
import UIKit
class testingViewController: UIViewController {
@IBOutlet weak var testLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showDatePicker))
tap.numberOfTouchesRequired = 1
tap.numberOfTapsRequired = 1
testLabel.addGestureRecognizer(tap)
testLabel.isUserInteractionEnabled = true// after adding this it worked
// Do any additional setup after loading the view.
}
func showDatePicker(){
print("testing")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3267 次 |
| 最近记录: |