Buttons

Add the button to the storyboard
1. Go to Main.storyboard
2. At the bottom right hand corner of the screen, click on the circle with the square inside it (the object library).
3. Scroll down and look for 'button'.
4. Drag and drop it into the storyboard.

Change the look/properties of the button
1. At the top right corner, click on the attributes inspector.
2. Change the font, colour, etc...

Connect the button to the code:
1. Click on the assistant editor at the top right hand corner of the screen (two circles, above the identity inspector).
2. Press the control button on your keyboard, click on the button in your storyboard.
3. A line will appear. Drag the line over to the ViewController, beneath the viewDidLoad function and somewhere between functions. Release the mouse.
4. Choose outlet under connection, give the button the name and click on connect.
5. Repeat steps 2 to 3, this type, choose the connection 'action' and give it a unique name. Set type to Any if it affects other labels and UI elements.
6. The event Touch Up Inside means that it is a simple press and release click.
7. Click on the 'Standard editor' button which is next to the 'Assistant editor' button. (This gets ride of the assistant editor view)
8. Go to ViewController.swift. Add code to the function that you created in steps 5 to 6.

To edit the font:
1. In the attributes inspector, select font.
2. Then, under font family, select custom and choose the family of the font.

Notes
- An outlet is connected to a button, it give it interactivity when clicked.


Duplicate a button
Select the button
Press command+C.
Select someone else on the screen.
Press command+V.

Setting the width and height of a button
Go to the size inspector.
Set the width and height.

Go to 'Add new constraints'.
Select width and height and key in the width and height.

Notes
Button size should at least be 44 x 44
If there are red lines around it, it means that it still has constraints not given, like where to constrain it on a screen.


Comments

Popular posts from this blog

Setting up a playground

Go to another page