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