1. - (void)addSubview:(UIView *)view 这是最常用的方法有两个注意点
2. - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
1 UILabel *testLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)]; 2 [testLbl setText:@"test"]; 3 4 UIView *testV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)]; 5 testV.backgroundColor = [UIColor greenColor]; 6 7 [self.window insertSubview:testV atIndex:5]; 8 [self.window insertSubview:testLbl atIndex:4];
以上代码中靠前的是testLbl。
3. - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
[self.window insertSubview:testLbl aboveSubview:nil];
4. - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
原文:http://www.cnblogs.com/ieso-ios/p/5115795.html