Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference between `self.backgroundcolor` and `self.layer.backgroundcolor`?

@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];

In a custom UIView, e.g. above, it seems the self.backgroundColor and self.layer.backgroundColor is the same. Is self.backgroundColor a wrapper for self.layer.backgroundColor?

like image 819
Jichao Avatar asked Feb 06 '23 16:02

Jichao


1 Answers

Is self.backgroundColor a wrapper for self.layer.backgroundColor?

Yes, that is exactly what it is. The same is true of frame, of alpha and opacity, and various other properties (not to mention the fact that the drawing in the view is actually the drawing in the layer).

A view and its underlying layer are very initimately bound up. In a sense, the view exists only to endow the layer with the ability to receive touches.

like image 51
matt Avatar answered Apr 29 '23 17:04

matt