UIView Profile What is UIView
UIViewis a piece of the window 区域 , is all the controls in iOS 基类 , all we can see in the app is directly or indirectly inherited and UIView. We call it UIView 视图 .
The role of UIView
- Responsible for content rendering within the internal area.
- The touch event that is responsible for the internal area.
- Manages all the child views of itself.
- Handles the basic animation.
UIView Create and use Create UIView
//通过frame创建View UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100100200200)]; //添加到父视图中 [self.window addSubview:view];
The view is an area, so the creation of UIView needs to set his 位置 and 大小 , frame is a body containing the position and size 结构 ;
Basic properties of UIView
//Set the background color of the viewView. BackgroundColor= [UicolorRedcolor];//Modify the size or position of the viewView. Frame= CGRectMake ( $, -, $, $);//Set the transparency of the view [0.0, 1.0]View. Alpha=0.5;//Set whether to hideView. Hidden=NO;//Set the label of the ViewView. Tag= -;//Center pointView. Center= Self. Window. Center;
Note : Here, specifically frame , he is uiview a very important attribute, determines the size and position of the UIView, the position set in the frame is based on the uiview 父视图 coordinate system, the need to pay special attention to不可以修改frame中的某个成员变量,只能整体修改frame
Child View Management
- Nsarray *subviews
- Manage all of the child Views (controls)
- The order of the array elements determines the display hierarchy order of the child controls (the larger the subscript, the more it appears above)
- Management of all child views is the
subviews management of arrays
Add a View
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(00100100)]; view2.backgroundColor = [UIColor greenColor]; view2.tag200; //将view2添加到view上 [view addSubview:view2];
After the above code is added, view2 is the view child view view , is view2 the parent view;
There is a hierarchy level relationship between all views, the more The view is added at the bottom, the more it appears above, and the previous one added below
Insert View
//将一个yView插入到view的子视图中,序号为0的位置 //序号越小越靠近下面,序号越大越靠近上面 //序号的范围[0,子视图的个数) [view insertSubview:yView atIndex:0]; //将oView插入到view的子视图中view2的下面 [view insertSubview:oView belowSubview:view2]; //将人View插入到view的子视图中, yView的上面 [view insertSubview:rView aboveSubview:yView];
Delete a view
UIView neutron view management and arrays the management of the elements is not the same, he cannot delete by 父视图 deleting 子视图 , can only 子视图自己 remove himself from the parent view.
//view2将自己从父视图中移除 [view2 removeFromSuperview];
Get view
The view has no name, but he does 标识 , so to get the view 指定子视图 , we can get it through the child view's identity, as follows:
//获取view下子视图标识为200的视图 UIView *subView = [view viewWithTag:200];
Change the display level of a view
//通过父视图,将某个子视图在最上面显示 [view bringSubviewToFront:yView]; //通过父视图, 将某个子视图在最下显示 [view sendSubviewToBack:view2];
This article simple book Link: http://www.jianshu.com/p/1f28240babd0
UIView of IOS UI base controls