Uikit Framework (2) Introduction

Source: Internet
Author: User

    • Uikit Frame

What is a framework?

Simply put, the other siege lion developed the code, including library files, header files, and so on, these files in the API we can come up with the use of

What does the Uikit framework do?

Provides classes for creating a touch-based user interface

Include: drawing mechanisms on the screen, capturing events, managing complex UI elements for your organization


The two most important classes in the Uikit?

1) UIView: All visible components/controls/views of the parent class

such as: UIButton button, Uilabel tag, uitextfield input box, uiimageview picture view, etc.

2) Uiviewcontroller: Parent class of all controllers, responsible for managing a page

such as: Uiviewcontroller basic page, Uitableviewcontroller table View page, etc.

Both of these parent classes inherit from Uiresponder, which is known as the Responder (introduction later)

Uiresponder inherited from NSObject


    • Basic use of the controller

In MVC design mode, the controller is responsible for the relationship between the view and the model data, and completes the logical function of the page.


Uiviewcontroller contains a very important property: The View in the page

@property (nonatomic, retain) UIView *view

Code Creation Controller:

Uiviewcontroller * VC = [[Uiviewcontroller alloc] init];

Controller Object VC, which is a page in an app that contains a white blank view


Set the app's initial page (under the empty template):

Find the following methods in the Appdelegate file

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

Add code at the comment location:

Create a Controller object and set its view background color

Set the root controller (initial page) of the Window object to the newly created controller

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/85/wKioL1bSnHeQG19QAAIJ4g7yURQ828.png "title=" 2bcc1150-d8cd-4e62-84d5-45b4924fe99c.png "width=" 699 "height=" 213 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width : 699px;height:213px; "alt=" Wkiol1bsnheqg19qaaij4g7yurq828.png "/>

Explain in detail the following code procedures for starting the empty project:

1) Create a UIWindow object whose size is the size of the current screen

2) Create a controller

3) Set the root controller of the Window object (initial page)

4) Set Window object to key window and display


What is key window?

That is, the main window, at the same time only one window is the main window

The main window can receive various events, such as touch events, motion events, keyboard events, and so on.

The parent class of UIWindow is UIView


    • Controller sub-class

For the use of Uikit, one is to take it directly to use, the second is to implement sub-class

The benefit of implementing subclasses is that the operation is encapsulated (cohesion-poly low coupling)

Controller sub-class:

such as Uiviewcontroller sub-class Amviewcontroller

Several methods in the controller should be overridden:

Init method: Called when the Controller object is initialized after it is created

The parent class method should be called first in the method

You typically add view-independent operations to this method

Viewdidload method: The Controller object manages the view that is called when it is loaded

The parent class method should be called first in the method

You typically add view-related actions in this method

-(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view.}

    • Basic properties of UIView

Background color @property (nonatomic, copy) Uicolor *backgroundcolor//transparency @property (nonatomic) cgfloat alpha//View Object Id@property ( nonatomic) Nsinteger tag//whether to hide @property (nonatomic, Getter=ishidden) BOOL hidden//where Window@property (nonatomic, ReadOnly) UIWindow *window



    • Child view of UIView

UIView is a container object:

Each uiview is a container that can accommodate other uiview.

Accommodating other UIView UIView we call the parent control, which is accommodated by the UIView we call the child control.

The existence of child controls depends on the existence of the parent control, and the location of the child control is based on the parent control.

Related properties:

@property (nonatomic, ReadOnly) UIView *superview@property (nonatomic, readonly, copy) Nsarray *subviews


To add a child view:

Subview when displayed on the screen, is located in the upper Superview, add the method:

-(void) Addsubview: (UIView *) view

The subview of the same view shows the corresponding layer in the order in which they are added, the later the Subview is displayed on the upper level, and vice versa.

The Superview can be used to manage the subview layer directly. Related methods:

-(void) Insertsubview: (UIView *) View Atindex: (Nsinteger) index-(void) Insertsubview: (UIView *) View Abovesubview: ( UIView *) siblingsubview-(void) Insertsubview: (UIView *) View Belowsubview: (UIView *) siblingsubview-(void) Bringsubviewtofront: (UIView *) view-(void) Sendsubviewtoback: (UIView *) view-(void) removefromsuperview-(UIView *) Viewwithtag: (Nsinteger) tag


The location and dimensions of the child view:

The UIView object contains the following properties related to location and dimension:

@property (nonatomic) CGRect frame//Frame property (in parent view as coordinates origin) @property (nonatomic) cgrect bounds//bounds property (self-coordinate origin) @prope Rty (nonatomic) cgpoint Center//Center properties (with top view as coordinates origin) @property (nonatomic) Cgaffinetransform Transform//deform properties


The coordinate system of the view:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7C/86/wKioL1bSotiwbtYuAAEwOE6FaXk593.png "title=" Screenshot.png "width=" "height=" 389 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:350PX;HEIGHT:389PX; "alt=" Wkiol1bsotiwbtyuaaewoe6faxk593.png "/>


This article is from the "Teacheran" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1745774

Uikit Framework (2) Introduction

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.