Thursday, February 21, 2019

Clickable Label

We want a clickable label, add this line.
la.userInteractionEnabled=true
When clicked, we want it open new class.
Declare label.
var la: UILabel!
Set position, color text.
la = UILabel(frame: CGRect(x: 100, y: 30, width: 280, height: 25))
la.text = "Touch to open new class"
la.textColor = UIColor.orangeColor()
la.userInteractionEnabled=true
view.addSubview(la)
This is function to open new class.
func tap (g:UIGestureRecognizer) {
let vc = second()
self.presentViewController(vc, animated: true, completion: nil)
    }
Add this line in to viewDidLoad.
let t = UITapGestureRecognizer(target:self, action:#selector(ViewController.tap(_:)))
la.addGestureRecognizer(t)

Label now open a new class when we click.

No comments:

Post a Comment