码迷,mamicode.com
首页 > 其他好文 > 详细

UIViewSubviews多个views之间的关系

时间:2015-09-17 01:03:30      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *subView1 = [[UIView alloc] init];
    subView1.frame = CGRectMake(50, 50, 100, 100);
    [self.view addSubview:subView1];
    subView1.backgroundColor = [UIColor redColor];
    subView1.tag = 1;
    
    UIView *subView2 = [[UIView alloc] init];
    subView2.frame = CGRectMake(70, 70, 100, 100);
    subView2.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:subView2];
    subView2.tag = 2;
    
    UIView *subView3 = [[UIView alloc] init];
    subView3.frame = CGRectMake(90, 90, 100, 100);
    subView3.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:subView3];
    subView3.tag = 3;
    
    [self.view bringSubviewToFront:subView1];
    [self.view sendSubviewToBack:subView3];
    //[self.view exchangeSubviewAtIndex: 0 withSubviewAtIndex:2];

    [self.view insertSubview:subView2 aboveSubview:subView3];
    [self.view insertSubview:subView3 belowSubview:subView1];

    //subView2.hidden = YES;
    
    for(UIView *v in self.view.subviews)
    {
        NSLog(@"tag = %ld",v.tag);
    }

    //[subView3 removeFromSuperview];
    for(UIView *v in self.view.subviews)
    {
        NSLog(@"%ld",v.tag);
    }
    
}
@end

技术分享

 

UIViewSubviews多个views之间的关系

标签:

原文地址:http://www.cnblogs.com/wanghengheng/p/4814952.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!