Learn iOS development from scratch (2): Hello world!

Source: Internet
Author: User

I am a little flattered to see so many replies and encouragement. Thank you for your support. I will try my best to record the process of learning iOS and share it with you.

Today I read the second chapter of the book, which mainly introduces how to use xcode and some necessary instructions. Finally, I made a "Hello world !" Is to display "Hello World!" with a label on the screen !", I did not write a line of code, drag the control, change the label font size or color, or something, it is relatively simple. Next I will write this process, the instructions for using xcode are not described here. I will introduce it wherever it is used.

1) Start xcode

Select create a new xcode project to create a new project.

2) Select a template and select the "single view application" template

"Single view application" for a single view application, xcode will create a main view by default (you can simply think of it as a panel in Visual Studio, a container ), then all other elements are placed on this main view, and the entire "Hello world!" There is only one label. You can select this template.

3) enter the name of the project to be created: Hello World

In the product name field, enter "Hello world". Company identifier is an identifier that indicates the company to which the program belongs (in my opinion, you can write anything at will, if you like it, but it seems that it is okay if you do not fill it out, but it is learning.) If you want to keep the default status, select "Next ".

4) select the location where the project is saved to complete the creation.

I simply save the project on the desktop, and click the "Create" button to create a simple project.

The procedure is similar to creating a project in Visual Studio.

After the project is created, xcode displays the following: the interface is still quite unfamiliar. Many things are seen for the first time. What you can recognize at a glance is the leftmost project navigation bar (project navigator, similar to the solution window in Visual Studio) and the control library in the lower right corner (Object Library, similar to tools in Visual Studio), other things still need to be familiar with a little bit.

5) Add a label Control
First, select the "bidviewcontroller. XIB" file in the project navigator.XCode'sINterfaceBUilder, which is used to manage the interface for user interaction.) After the selection, xcode will look like the following. An iPhone interface will appear, and the control will be dragged to it later.

Next, find the label control in the control bar (Object Library), drag it to the interface, and place it in any position you like. I put it in the upper, lower, and left plays (there will be guides, help you place them ). These operations are not much different from Vs and are very familiar with them.

Change the display text of the label and double-click the label. Then, the text in the label will be selected and changed to "Hello World. The operations here are somewhat different from those in vs. If you double-click a control in Vs, it is likely that you add a mouse-click event for the control, while in xcode, only the display text of the control is changed. After the changes, adjust the position of the control to the position in the upper, lower, and lower plays. After the changes, the interface is as follows.

If you want to change the label font, color, and so on, select the label, and the label attribute bar will appear on the right side of xcode. You can directly change the label in the attribute, which is also very simple, this operation is similar to.

6) Compile and run
All right, at this point, all operations should have been completed, and the last step is to compile and run. Click the "run" button in the upper left corner (shortcut key: Command + R, build shortcut key: command + B), compile and run.

An iphone simulator is displayed, and the Hello world is displayed on the iPhone, as shown in.

So far, the first iPhone program has been completed, which is very simple and has not been written in any line of code.

7) Replace the program icon
The above Hello world has some flaws. When you click the Home Key of the simulator to return to the desktop, you will find that the hello World icon is gray (the iPhone default icon for programs without icons), see

The reason for this is very simple. We didn't set its icon. To add the icon, go back to xcode and select the program root node (the top node of the blue icon) in the project navigator on the left)

After selection, the "app icons" column will appear in the middle of xcode, which contains two icons, one of which is a normal resolution (for non-Retina screen iPhone, 3gs or iPhone earlier than it), and high resolution (for Retina screen, iPhone 4 and later models)

Only images with a general resolution can be selected. You can only select an image on the left, right-click the icon on the left, select select file, and select an image.
 

Then re-compile and run the program. After the program is displayed in the iPhone simulator, click home to return to the desktop. At this time, Hello world already has its own icon. This process is also very simple.

 

Summary:
In the second chapter, apart from introducing some usage and layout of xcode, the process of creating the first iPhone application is very simple, it makes you feel that creating an iPhone is not as difficult as you think, and you are interested in iPhone development.

Now, this learning record is here. In the next chapter, we will learn how to add buttons for the app, the design pattern of the iPhone app (MVC: Model-View-Controller ), compared with this Chapter, the content will be more enriched and more difficult.

 

Thank you!

Hello_world.zip

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.