IOS学习(二)父子视图

来源:互联网 发布:百度关键词优化方案 编辑:程序博客网 时间:2024/06/05 14:25
-(void)viewDidLoad{    [super viewDidLoad];        self.view.backgroundColor = [UIColor whiteColor];            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)];    view1.backgroundColor = [UIColor redColor];        UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 100, 100)];    view2.backgroundColor = [UIColor blueColor];        [self.view addSubview:view1];        [view1 addSubview:view2];        //view2添加到view1中时,view2的视图区域会超出view1,设置这个参数之后,会做自动截取处理    [view1 setClipsToBounds:true];        UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(70, 70, 100, 100)];    view3.backgroundColor = [UIColor greenColor];        //插入view的机种方式    [self.view insertSubview:view3 atIndex:1];//    [self.view insertSubview:view3 aboveSubview:view2];//    [self.view insertSubview:view3 belowSubview:view2]    }

0 0