#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