11
App Development with Swift Xcode - Multiple Screens and URL Links Start your Xcode project and create four new image file sets under Assets.xcassets: Save images to your downloads area and drag them to your 2x image holder

dbm2014.stlwebdev.usdbm2014.stlwebdev.us/documents/xcode_MultScreens_…  · Web viewApp Development with Swift . Xcode - Multiple Screens and URL Links. Start your Xcode project

  • Upload
    lynhi

  • View
    230

  • Download
    2

Embed Size (px)

Citation preview

App De-velopment

with Swift

Xcode - Multiple Screens and URL Links

Start your Xcode project and create four new image file sets under Assets.xcassets:

Save images to your downloads area and drag them to your 2x image holder

Switch to your Main.storyboard area and move a second view controller from your object library (may have to adjust your zoom)

Add 4 buttons, 3 on your home screen, and one on your secondary screen

Highlight one button, and under the Attributes Inspector, change the button title to your image, and choose the image under Attribures. Resize the image as you need to.

Repeat choosing and resizing the other three buttons with their images

Highlight the first top button image on your home screen. Hold down the control and mouse drag buttons and go over to anywhere on your secondary screens. Highlight and choose the Show Detail option on your small Action Segue window.

Repeat the previous step with the top image on your secondary screen, going from the secondary screen with control / mouse drag to your home screen.

Turn on the Assistant Editor, and depress the Navigator and Utilities areas. High-light the middle button, control and mouse drag from the button to a line right be-fore the last } bracket in ViewController.Swift. Choose Connection=Action, give a name to the image, Type=UI Button, and click Connect.

In ViewController.Swift , hit the Enter key a couple times to give space between the { } brackets just put in on the IBAction button. Paste the following code in between the brackets:

if let url = URL(string: "http://www.foxmovies.com/movies/logan") { UIApplication.shared.openURL(url) }

Paste into the double quotes section the URL or web address you want the button to take you to when you press it. Make sure you have the http:// section in there with the web address.

Repeat the last two steps for the bottom button on the home screen, copying a differ-ent website to go to inside the double quotes.

Choose File - Save. Click on Run to test the Simulator. On the top buttons, you should be able to switch between screens. On the middle and bottom buttons, they will take you to your desired website on the simulator.