How to Create a Button for an iOS App Using XCode


This tutorial introduces you to how to install XCode and use it to create an iOS app and create a simple button using Swift.

Part 1
Installing XCode and Swift

Installing XCode and Swift on How to Create a Button for an iOS App Using XCode

1
Create an Apple ID and an iTunes account. Go to the Apple Store on a Macbook computer and in the search box, type in XCode.

Installing XCode and Swift on How to Create a Button for an iOS App Using XCode

2
XCode should be the first result in the search. Click on it and begin the download. It may ask for an Apple ID password before it begins installation

Installing XCode and Swift on How to Create a Button for an iOS App Using XCode

3
Wait for the installation to complete. The app is about 8 gigabytes in size. Depending on internet speed, the download time may vary.

Installing XCode and Swift on How to Create a Button for an iOS App Using XCode

4
Once downloaded, launch the app. It will ask to install additional components in order for the app to run properly. Click Install. This download should take a few minutes to complete.

Part 2
Setting Up a Project

Setting Up a Project on How to Create a Button for an iOS App Using XCode

1
Upon opening, the program will display a menu of options. Click on Create a new XCode project to get to the project template screen.

Setting Up a Project on How to Create a Button for an iOS App Using XCode

2
After creating a new project, the program will ask to select a standard template. Click on Single View App to create a blank program.

Setting Up a Project on How to Create a Button for an iOS App Using XCode

3
The screen will display multiple options to organize project details. Select Swift as the language. Name the file and click next.

Setting Up a Project on How to Create a Button for an iOS App Using XCode

4
XCode will ask where to save the project repository. Choose a folder that is easy to access. In order to re-open the project, XCode will need the entire folder to begin where you last ended. Once selected, click Create.

Setting Up a Project on How to Create a Button for an iOS App Using XCode

5
At the top right of the program, select "Assistant Editors on the Right." This will bring the iOS screen layout to the right side of the program for easy viewing.

Part 3
Creating the Button

Creating the Button on How to Create a Button for an iOS App Using XCode

1
To add features, click on the "Objects" option to display a list of objects. Click on the "button" icon and drag it anywhere onto the "ViewController" screen.

Creating the Button on How to Create a Button for an iOS App Using XCode

2
Once finalized, click on the button while holding the control button on the keyboard and drag the line into an empty spot on the "Main.storyboard"panel code between the { and } brackets between lines 16-22.

Creating the Button on How to Create a Button for an iOS App Using XCode

3
Once dragged, an options menu will pop up, requiring selections for object creation. To make a button that the user can interact with, select UI Button. Name the button as button1.

Creating the Button on How to Create a Button for an iOS App Using XCode

4
Once completed, a block of code will appear in the “Main.storyboard” panel. Place the following line of code in between the two {} brackets: sender.backgroundColor = UIColor.blue

Creating the Button on How to Create a Button for an iOS App Using XCode

5
Click the "Build and Run" icon to execute your app. Depending on the processing power of the laptop, this execution time can last from either a few seconds to a couple of minutes.

Creating the Button on How to Create a Button for an iOS App Using XCode

6
View the app and check for the "Button" text on the white menu.

Creating the Button on How to Create a Button for an iOS App Using XCode

7
Click the button to activate the code and change the color to blue.