直接上代碼
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(10, 50, 100, 50)];
view1.backgroundColor = [UIColor blueColor];
[self.view addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(15, 55, 100, 50)];
view2.backgroundColor = [UIColor grayColor];
[self.view addSubview:view2];
//如果將下面兩行代碼都註釋掉 view1 會在下面 view2會在上面
// 下面這行代碼能夠將view2 調整到父視圖的最下面
// [self.view sendSubviewToBack:view2];
//將view調整到父視圖的最上面
[self.view bringSubviewToFront:view1];
}