Ios-ui operation of the view under parent view

Source: Internet
Author: User

Create three views on a window:

Orange v1.

UIView *v1 = [[UIView Alloc]initwithframe:cgrectmake (+, ()];

V1.backgroundcolor = [Uicolor Orangecolor];

[Self.window ADDSUBVIEW:V1];

Black v2.

UIView *v2 =[[uiview Alloc]initwithframe:cgrectmake (a);

V2.backgroundcolor = [Uicolor blackcolor];

[Self.window Addsubview:v2];

The Green v3

UIView *v3 =[[uiview alloc]initwithframe:cgrectmake (n., +)];

V3.backgroundcolor = [Uicolor Greencolor];

[Self.window Addsubview:v3];

The order in which the views are initialized is to place the view survival in the Subviews array class.

The location of the parent view is 0 after you join the parent view +1

Changing the position of the view is changing the position of the elements inside the subviews array.

Now running program Simulator shows the following results:

Now let's move the Orange view V1 to the top :

[Self.window bringsubviewtofront:v1]; The results are as follows:

Originally in the bottom of the window view V1 now on the top of the

Now comment out the previous method and move the view V3 to the bottom

[Self.window Sendsubviewtoback:v3];

We know the subscript for all added views in the Subviews array

Now swap the positions of two views v1 and v3

[Self.window Exchangesubviewatindex:1withsubviewatindex:3];

Now let's try creating a new view and adding it to the top or bottom of the desired existing view.

New Add a purple view Insertview

UIView *insertview = [[UIView alloc]initwithframe:cgrectmake (80, 250, 80, 150)];

Insertview.backgroundcolor = [Uicolor Purplecolor];

[Self.window Addsubview:insertview];

Insert a view to view v1 above

[Self.window Insertsubview:insertview Abovesubview:v1;

Comment out the previous sentence add the purple view to the Green View V3

[Self.window Insertsubview:insertsubview belowsubview:v3];ways to remove a view:

[view name Removefromsuperview];

Tag tag : ID number of the same parent view as tag label

Insertview.tag = 100;

This view can be found on his parent view through the tag value

Viewwithtag: Find a view with no tag value on a parent view

UIView *v = [Self.window viewwithtag:100];

Then V is insertview.

V.backgroundcolor = [Uicolor Redcolor];

Ios-ui operation of the view under parent view

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.