Shape Add Shadow

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.