【技巧】View的Frame与Bounds区别

摘自 ios view的frame和bounds之区别(位置和大小)

事例代码

  UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 250)];  
  [view1 setBounds:CGRectMake(-20, -20, 280, 250)];
  view1.backgroundColor = [UIColor redColor];  
  [self.view addSubview:view1];//添加到self.view    

  UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];  
  view2.backgroundColor = [UIColor yellowColor];  
  [view1 addSubview:view2];//添加到view1上,[此时view1坐标系左上角起点为(-20,-20)]  

下图说明一切~


【技巧】View的Frame与Bounds区别_第1张图片
Paste_Image.png

你可能感兴趣的:(【技巧】View的Frame与Bounds区别)