Calayer *sublayer =[Calayer layer]; Sublayer.backgroundcolor=[Uicolor Purplecolor]. Cgcolor; Sublayer.shadowoffset= Cgsizemake (0,3); Sublayer.shadowradius=5.0; Sublayer.shadowcolor=[Uicolor Blackcolor]. Cgcolor; Sublayer.shadowopacity=0.8; Sublayer.frame= CGRectMake ( -, -, -,192); Sublayer.bordercolor=[Uicolor Blackcolor]. Cgcolor; Sublayer.borderwidth=2.0; Sublayer.cornerradius=10.0; [Self.view.layer Addsublayer:sublayer]; Calayer*imagelayer =[Calayer layer]; Imagelayer.frame=Sublayer.bounds; Imagelayer.cornerradius=10.0; Imagelayer.contents= (ID) [UIImage imagenamed:@"Snaguosha.png"]. Cgimage; Imagelayer.maskstobounds=YES; [Sublayer Addsublayer:imagelayer]; Calayer*customdrawn =[Calayer layer]; Customdrawn.Delegate=Self ; Customdrawn.backgroundcolor=[Uicolor Greencolor]. Cgcolor; Customdrawn.frame= CGRectMake ( -, -,280, $); Customdrawn.shadowoffset= Cgsizemake (0,3); Customdrawn.shadowradius=5.0; Customdrawn.shadowcolor=[Uicolor Blackcolor]. Cgcolor; Customdrawn.shadowopacity=1; Customdrawn.cornerradius=10.0; Customdrawn.bordercolor=[Uicolor Blackcolor]. Cgcolor; Customdrawn.borderwidth=2.0; Customdrawn.maskstobounds=YES; [Self.view.layer Addsublayer:customdrawn]; [Customdrawn Setneedsdisplay];
The above code previews are as follows:
You can see that there are no shadows in the bottom section. Watching for a long while did not see what is different, and later found that because customdrawn.maskstobounds = yes, this code does not exist, if you remove this line of code will be like this:
The shadow came out, but the fillet was gone. The solution is very simple, like the picture above the way, inside a layer, maskstobounds action in the inner layer, the outer shadow of the display
Ios--calayer Shadow Invalid Problem