IOS stage study 28th-day notes (UIView Introduction), iosuiview
IOS Learning (UI) knowledge point sorting
1. Introduction to UIVIew
1) concept: UIView is a large container used to load and display various controls. It is the base class of all UI controls in iOS.
2) UIView instance initialization code
1 UIView * view1 = [[UIView alloc] init]; 2 view1.frame = CGRectMake (0, 20, self. view. frame. size. width, self. view. frame. size. height/2); 3 view1.backgroundColor = [UIColor lightGrayColor]; 4 view1.tag = 1000; 5 6 // set the transparency of the view in the alpha attribute. 7 view1.alpha = 0.5; 8 9 // the excess part is automatically hidden 10 view1.clipsToBounds = YES; 11 [self. view addSubview: view1];
3) The parent view of sendSubviewToBack can be placed at the lowest level using the sendSubviewToBack method.
For example:
1 UIView * view3 = [[UIView alloc] init]; 2 view3.frame = CGRectMake (45, 45,240,260); 3 view3.backgroundColor = [UIColor blueColor]; 4 view3.tag = 1001; 5 [view1 addSubview: view3]; 6 7 // The parent view places a subview on the bottom 8 [view1 sendSubviewToBack: view3];
4) The bringSubviewToFront parent view can be placed on the top of the parent view using the sendSubviewToBack method.
For example:
1 UIView * view2 = [[UIView alloc] init]; 2 view2.frame = CGRectMake (40, 40,250,250); 3 view2.backgroundColor = [UIColor blackColor]; 4 view2.tag = 1001; 5 [view1 addSubview: view2]; 6 7 // The parent view places a subview on the top 8 [view1 bringSubviewToFront: view2];
5) obtain all subviews in self. view, for example:
1 NSArray *subViews = self.view.subviews;
6) removeFromSuperview removes the child view from the parent view. For example:
1 [view1 removeFromSuperview];
7) viewWithTag:
1 UIView *view = [self.view viewWithTag:1000];
8) hidden view:
1 view.hidden = YES;
9) because all UI controls inherit from UIVIew, you can use viewWithTag to obtain control objects based on the Tag of the control.
For example:
1 // 1000 indicates the Tag of the button. Note: A strong conversion is required. 2 UIButton * button = (UIButton *) [self. view viewWithTag: 1000];