1 Preface
Use the Cgcontextsetshadow procedure to apply a shadow to a shape that is drawn on a graphical environment.
Cgcontextsetshadowwithcolor process: This procedure takes exactly the same parameters as the Cgcontextsetshadow, but adds a cgcolorref-type parameter to set the color of the shadow.
2 code Examples
zyviewcontrollerview.m
[Plain]-(void) DrawRect: (CGRect) rect{
[Self drawrectattopofscreen];
Since the first rectangle is already shaded, it is not set when the second rectangle is plotted.
[Self drawrectatbottomofscreen];
}
-(void) drawrectattopofscreen{
Cgcontextref CurrentContext = Uigraphicsgetcurrentcontext ();
Set the background color in gray
/* Second parameter: The displacement of the shadow, specified by the Cgsize type value, starting from the lower-right part of each shape to apply the shadow. The larger the X-value of the displacement, the shape
The shadow on the right spreads farther. The greater the Y value of the displacement, the lower the lower shadow.
The third parameter: the blur value of the shadow, specified as a floating-point value (cgfloat). Specifying 0.0f causes the shadow to become solid shape. The higher the value, the more shadows
Fuzzy. We can see the example very soon.
*/
Cgcontextsetshadowwithcolor (Currentcontext,cgsizemake (10.0f, 10.0f), 20.0f,[[uicolor Graycolor] CGColor]);
/* Create the path first. Just the path handle. */
Cgmutablepathref path = cgpathcreatemutable ();
CGRect firstrect = CGRectMake (55.0f, 60.0f,150.0f, 150.0f);
Cgpathaddrect (Path,null, firstrect);
Cgcontextaddpath (currentcontext, path);
[[Uicolor colorwithred:0.20f green:0.60f blue:0.80f alpha:1.0f] Setfill];
Cgcontextdrawpath (CurrentContext, Kcgpathfill);
Cgpathrelease (path);
}
-(void) drawrectatbottomofscreen{
Cgcontextref CurrentContext = Uigraphicsgetcurrentcontext ();
Cgmutablepathref Secondpath = cgpathcreatemutable ();
CGRect secondrect = CGRectMake (150.0f, 250.0f, 100.0f,100.0f);
Cgpathaddrect (Secondpath, null,secondrect);
Cgcontextaddpath (CurrentContext, Secondpath);
[[Uicolor Purplecolor] setfill];
Cgcontextdrawpath (CurrentContext, Kcgpathfill);
Cgpathrelease (Secondpath);
}
-(void) DrawRect: (CGRect) rect{
[Self drawrectattopofscreen];
Since the first rectangle is already shaded, it is not set when the second rectangle is plotted.
[Self drawrectatbottomofscreen];
}
-(void) drawrectattopofscreen{
Cgcontextref CurrentContext = Uigraphicsgetcurrentcontext ();
Set the background color in gray
/* Second parameter: The displacement of the shadow, specified by the Cgsize type value, starting from the lower-right part of each shape to apply the shadow. The larger the X-value of the displacement, the shape
The shadow on the right spreads farther. The greater the Y value of the displacement, the lower the lower shadow.
The third parameter: the blur value of the shadow, specified as a floating-point value (cgfloat). Specifying 0.0f causes the shadow to become solid shape. The higher the value, the more shadows
Fuzzy. We can see the example very soon.
*/
Cgcontextsetshadowwithcolor (Currentcontext,cgsizemake (10.0f, 10.0f), 20.0f,[[uicolor Graycolor] CGColor]);
/* Create the path first. Just the path handle. */
Cgmutablepathref path = cgpathcreatemutable ();
CGRect firstrect = CGRectMake (55.0f, 60.0f,150.0f, 150.0f);
Cgpathaddrect (Path,null, firstrect);
Cgcontextaddpath (currentcontext, path);
[[Uicolor colorwithred:0.20f green:0.60f blue:0.80f alpha:1.0f] Setfill];
Cgcontextdrawpath (CurrentContext, Kcgpathfill);
Cgpathrelease (path);
}
-(void) drawrectatbottomofscreen{
Cgcontextref CurrentContext = Uigraphicsgetcurrentcontext ();
Cgmutablepathref Secondpath = cgpathcreatemutable ();
CGRect secondrect = CGRectMake (150.0f, 250.0f, 100.0f,100.0f);
Cgpathaddrect (Secondpath, null,secondrect);
Cgcontextaddpath (CurrentContext, Secondpath);
[[Uicolor Purplecolor] setfill];
Cgcontextdrawpath (CurrentContext, Kcgpathfill);
Cgpathrelease (Secondpath);
}
Shape Add Shadow