代码之家  ›  专栏  ›  技术社区  ›  Jichao

“自我”之间的任何区别。backgroundcolor和self.layer.backgroundcolor?

  •  5
  • Jichao  · 技术社区  · 8 年前
    @implementation AVSuperView
    
    - (AVSuperView*)initWithFrame:(CGRect)frame{
        if (self = [super initWithFrame:frame]) {
    //        self.backgroundColor = [UIColor redColor];
            self.layer.backgroundColor = [[UIColor redColor] CGColor];
            AVLayout* avLayout = [[AVLayout alloc] init];
    

    在自定义UIView中,例如上面,似乎 self.backgroundColor self.layer.backgroundColor 是一样的。是 包装纸 self.layer.backgroundColor ?

    1 回复  |  直到 8 年前
        1
  •  8
  •   matt    8 年前

    self.backgroundColor 包装纸 self.layer.backgroundColor ?

    是的,这就是事实。同样的道理 frame 属于 alpha opacity ,以及各种其他特性(更不用说视图中的图形实际上是图层中的图形)。

    视图及其底层是非常初始绑定的。在某种意义上,视图的存在只是为了赋予层接收触摸的能力。