The first iOS program that displays "Hello World" on the interface

Source: Internet
Author: User

1. How to create a new project

Ios->single View application-> project name, save location

2. Run the app

Click the triangle symbol or use the shortcut key (Command + R)

Shortcut key: Command+b just compile, not run

3. Composition of project documents

4. How does the application work?

1) Main method

int main (int argc, char* argv[])
{
@autoreleasepool {
Return Uiapplicationmain (argc,argv, Nil, Nsstringfromclass ([Appdelegateclass]));
}

Uiapplicationmain () global function, altogether three things were done:

A) Create an instance of the application class based on the third parameter

b) Create an instance of the application proxy class according to the fourth parameter

c) Start the event loop

d) in the proxy class didfinishlaunchingwithoptions: Create and display the interface after writing the startup program in the method

5.UIWindow

1) What is it? Is the basic object of the interface display, you must first create an instance of the window to display the content.

2) What is the role? is the parent container of the content to be displayed by the interface, and the other displayed content is added on top of the window.

6.frame

1) What is it? is a struct of the CGRect type

2) describes the position and size of the control in the parent container

Cgrect{cgpoint origin, cgsize size} cgpoint{cgfloat x, cgfloat y} cgsize{ CGFloat width, cgfloat height}


3) How do I create a variable for a struct?

Use global function xxxmake();

Cgrect-> CGRectMake (x,y,width,height)

Cgpoint-Cgpointmake (x, y);

Cgsize, Cgsizemake (width,height);

7. Application design concept: View controllers (Viewcontroller) and Views (view)

7.1 The role of the view: responsible for the appearance of the display

7.2 The role of the controller: Create an interface, manage the life cycle of the view

7.3 The relationship between view and Viewcontroller: The system's Uiviewcontroller is inherently a view that accesses the controller's own view with the Self.view property

7.4 Viewdidload method: When a view is created, it is called automatically and is called only once , and the initialization of views about the view is placed in this method

7.5 Steps to use VC:

Step1: Write a class that inherits from Uiviewcontroller

Step2: Overriding the Viewdidload method in the class to create the interface content

Step3: In the Didfinishlaunching method, create an instance of window, create an instance of the VC, set the VC to Window's Rootviewcontroller (root vc), display window

8. Views (UIView) and controls (Uicontrol)

8.1 What is a view?

There is a look, see the view is all.

8.2 What is a control?

A special view, which is a subclass of Uicontrol, not only has a certain display appearance, but also responds to advanced events and interacts with the user. Uilabel is strictly not a control because label cannot respond to user events

8.3 Understanding of terminology:

View: A larger display area that can hold controls and make containers

Control: A child element contained in a container

9.UILabel Label

What is 9.1?

Display controls for static text content

9.2 Common Properties

Text: Display of textual content

Font: Font of text displayed

NumberOfLines: The default is 1, the maximum number of rows displayed, and 0 indicates no upper limit

Linebreakmode: Line break mode

Adjustsfontsizetofitwidth: Whether to adjust the font size to fit the width of the control

10.UIButton button

10.1 What is a button?

A control that can interact with the user and can be clicked

10.2 How to create

10.3 Common Properties

10.4 Adding events

Homework:

1. Try the following properties for Uilabel and UIButton

. textcolor

. Font

. backgroundcolor

. tintcolor

2. Make a small application

There is a button in the interface, each press the button, the interface more than one Uilabel

Requirements:

1) distance between labels 10 dots apart

2) All label and screen left distance 20 points

3) All label width 280, height 20

4) Overlay the contents of each label (Hello,helloworld,helloworldworld,......)

3. Cases and attributes written in class memorize


-------------------------------------------------------------------------------------------

Summarize:

1.main.m file

Three things were done in the Main method: Two objects were created, event loops were started

2.window objects

3. Controller (Uiviewcontroller)

4. View (UIView)

5. Controls (Uicontrol)

6.UILabel and UIButton

7.frame

CGRect Structural Body

Cgpoint, Cgsize








This article is from "IOS" blog, declined reprint!

The first iOS program that displays "Hello World" on the interface

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.