iOS檢視層次管理sendSubviewToBack、bringSubviewToFront

samson_wang發表於2017-10-20
  • (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];
    }


相關文章