Note that there are some explanatory texts on larger screens.

plurals
  1. POCALayer, subLayer alpha overriding
    primarykey
    data
    text
    <p>I have a CALayer ( superlayer ) with 0.3 opacity property. The superlayer contains another CALayer(sublayer). Although sublayer does not have a opacity property superLayer's opacity affects sublayer's appearance. Is there a method that I can override superLayer'a opacity property.</p> <p><strong>SuperLayer</strong> </p> <pre><code>@implementation SuperView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setOpaque:NO]; [self.layer setOpaque:NO]; } return self; } -(void)drawRect:(CGRect)rect { CALayer* superLaer=self.layer; superLaer.backgroundColor = [UIColor blackColor].CGColor; superLaer.shadowOffset = CGSizeMake(0, 3); superLaer.shadowRadius = 5.0; superLaer.shadowColor = [UIColor blackColor].CGColor; superLaer.shadowOpacity = 0.6; superLaer.frame = CGRectMake(10, 10, 300,300); superLaer.borderColor = [UIColor blackColor].CGColor; superLaer.borderWidth = 2.0; superLaer.cornerRadius = 10.0; superLaer.cornerRadius = 10.0; superLaer.masksToBounds=YES; superLaer.opacity = 0.1; } @end </code></pre> <p><strong>SubLayer</strong></p> <pre><code>@implementation SubView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setOpaque:NO]; [self.layer setOpaque:NO]; } return self; } -(void)drawRect:(CGRect)rect { CALayer* superLaer=self.layer; superLaer.backgroundColor = [UIColor redColor].CGColor; superLaer.shadowOffset = CGSizeMake(0, 3); superLaer.shadowRadius = 5.0; superLaer.shadowColor = [UIColor blackColor].CGColor; superLaer.shadowOpacity = 0.6; superLaer.frame = CGRectMake(100, 100, 100,100); superLaer.borderColor = [UIColor blackColor].CGColor; superLaer.borderWidth = 2.0; superLaer.cornerRadius = 10.0; superLaer.cornerRadius = 10.0; superLaer.masksToBounds=YES; } @end </code></pre> <p>I have added the subView to the superView in Viewcontroller.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload