当我之前创建一个按钮时,它有能力成为“动作”IBA功能.
如何用标签创建相同的东西?所以当我点击标签时,我的应用程序将指向新页面. (如何将其指向新页面?我是否必须创建一个全新的视图并以某种方式将其链接到该页面)
请记住,我是一个全新的快速并且已经开始使用我的程序,但它是来自几个教程的部分,因此我可能很难第一次理解你的答案.
您可以使用UITapGestureRecognizer,以下是您的简单示例:
原文链接:/swift/319188.htmlimport UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let label = UILabel(frame: CGRectMake(0,200,21)) label.center = CGPointMake(160,284) label.textAlignment = NSTextAlignment.Center label.userInteractionEnabled = true label.text = "I'am a test label" self.view.addSubview(label) let gestureRecognizer = UITapGestureRecognizer(target: self,action: "handleTap:") label.addGestureRecognizer(gestureRecognizer) } func handleTap(gestureRecognizer: UIGestureRecognizer) { let storyboard = UIStoryboard(name: "Main",bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("next") self.presentViewController(vc,animated: true,completion: nil) } }
结果: