Swift iOS 24-Hour Trainer. Mishra Abhishek

Чтение книги онлайн.

Читать онлайн книгу Swift iOS 24-Hour Trainer - Mishra Abhishek страница 5

Swift iOS 24-Hour Trainer - Mishra Abhishek

Скачать книгу

with the text Label at center. At the bottom right, Label under Object library is selected and encircled, with arrow pointing from it to the text Label." target="_blank" rel="nofollow" href="#i000001960000.jpg"/>

Figure 1.9

      7. Change the text displayed in the Label to “Hello Swift” by editing the value of the Text attribute in the Attribute inspector.

      8. Position the label anywhere within the scene using the mouse.

      • Create layout constraints.

      1. Select the label in the storyboard scene by clicking on the label once. Change the size of the label so that the label is large enough to show the text “Hello Swift” fully. To do this use the Editor arrow Size To Fit Content menu item.

2. Select the label in the storyboard and bring up the Align constraints popup window by clicking the Align button at the bottom right corner of the storyboard (see Figure 1.10).

Figure 1.10

In this popup window, setup the following options (see Figure 1.11):

      • Horizontally in Container: Checked

      • Vertically in Container: Checked

      • Update Frames: All Frames In Container

Figure 1.11

      Click the Add 2 constraints button in the popup to apply these layout constraints to the label and dismiss the popup.

      NOTE

      Selecting All Frames in Container in the Update Frames combo box will force the scene to update the position of the label using the constraints you have just specified.

      • Set up a launch file.

      1. Select the LaunchScreen.Storyboard file in the project navigator.

      2. Use the Attribute Inspector to change the background color of the launch file to a different color than that of the scene in the main storyboard.

      • Set up an application icon.

      1. Select the Assets.xcassets item in the project navigator to open the asset bundle. Select the AppIcon asset within this bundle.

      2. Use drag-and-drop to assign images to the iPhone App and iPad App placeholders. You can obtain the images from the resources available for this lesson on the book's website at www.wrox.com/go/swiftios.

      • iPhone App 2x: Use the file iPhoneAppIcon2x.png.

      • iPhone App 3x: Use the file iPhoneAppIcon3x.png.

      • iPad App 1x: Use the file iPadAppIcon1x.png.

      • iPad App 2x: Use the file iPadAppIcon2x.png.

After these assignments are made, your scene should resemble Figure 1.12.

Figure 1.12

      • Test your app in the iOS Simulator by clicking the Run button in the Xcode toolbar. Alternatively, you can use the Project arrow Run menu item.

      REFERENCE

      To see some of the examples from this lesson, watch the Lesson 1 video online at www.wrox.com/go/swiftiosvid.

Lesson 2

      A Tour of Xcode and the iOS Simulator

      Xcode is Apple's IDE (integrated development environment), which you use to create iOS applications. The word “integrated” refers to the fact that Xcode brings together several different tools into a single application.

      Xcode contains several tools, but the ones you'll use most of the time are the source code editor, debugger, and the Interface Builder. At the time of this writing, the current version of Xcode is 7.0.

      The iOS Simulator is an application that runs on your Mac and allows you to test your apps without using an actual iOS device. The iOS Simulator is part of the standard iOS SDK installation. When you run your app in Xcode, you have the choice of launching it in the simulator or an actual device. If you choose to launch it in the simulator, Xcode will launch the iOS Simulator automatically.

      In this lesson, you explore various commonly used features of Xcode and the iOS Simulator.

      The Welcome Screen

When you launch Xcode, you are presented with the welcome dialog box (Figure 2.1). You can use the welcome dialog box to quickly create a new project, connect to a source code repository, open a recently used project, or create a Swift playground.

Figure 2.1

      The first step in creating an iOS application is to create an appropriate project in Xcode. An Xcode project has the file extension .xcodeproj and tells the Xcode IDE (among other things) the name of your application, what kind of application it is (iPhone/iPad/Universal), and where to find the code files and resources required to create the application.

      Creating a New Project

When you create a new project in Xcode, you first need to select a template on which to base the project. Xcode templates contain files that you need to start developing a new application. Xcode provides a list of project templates to select from (Figure 2.2).

Figure 2.2

      The Xcode template window has multiple template categories to choose from. In this book, you create iOS applications, and thus need to make sure the iOS template category is selected.

After you have selected a suitable template, Xcode presents the project options dialog box (Figure 2.3).

Figure 2.3

      This is where you provide the name of the project and the name of your company, choose the language (Objective-C or Swift), and specify the target

Скачать книгу