【技巧】View的Frame与Bounds区别

2015-08-06  本文已影响1129人  狂暴火鸡

摘自 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)]  

下图说明一切~


Paste_Image.png
上一篇 下一篇

猜你喜欢

热点阅读