Labels

Adding a label
1. Go to object library.
2. Drag and drop a label.

You can also type 'label' in the filter tab at the bottom of the object library.

Setting/getting the text of a label
nameOfLabel.text = String(nameOfNumberOrInteger)

If you need to refer to the text of a label for instance:

nameOfLabel.text = nameOfLabel.text! + "abc"

Remember to wrap it by adding the exclamation mark

Change background colour of label
1. At the attributes inspector, go to the top right hand corner and click 'hide' for labels.
2. The View tag will show.
3. Change the background colour.

You can set the number of lines that a label can have.

Animate labels so that they swish
UIView.animate(withDuration: 0.5) { 
            self.lab1.center.x += self.view.bounds.width

        }
Double click the second parameter to get to the code

OR:
UIView.animate(withDuration: duration, delay: delay, options: .curveEaseOut, animations: {
            object.center.x += self.view.bounds.width
        }) { (true) in
            
        }

Note:
Labels can be type cast as UIView

Comments

Popular posts from this blog

Setting up a playground

Go to another page