ios--Adding a shadow to a view

Source: Internet
Author: User

ios– Adding a shadow to a view: View add rounded corners, adding shadows
Yin Movie Figure Self. Viewshadow= [[UIView alloc]initwithframe:cgrectmake (0,0, -, -)];Self. Viewshadow. BackgroundColor= [Uicolor Redcolor];Self. Viewshadow. Layer. Shadowopacity=1;Self. Viewshadow. Layer. Cornerradius=5;Self. Viewshadow. Layer. BorderWidth=1;Self. Viewshadow. Layer. Maskstobounds= YES;Yin Movie Background Self. VIEWSHADOWBG= [[UIView alloc]initwithframe:cgrectmake ( -, -, -, -)];Self. VIEWSHADOWBG. Layer. Shadowopacity=1;Self. VIEWSHADOWBG. Layer. Shadowoffset= Cgsizezero;Self. VIEWSHADOWBG. Layer. Shadowcolor= [Uicolor Greencolor]. Cgcolor;Self. VIEWSHADOWBG. Layer. Shadowradius=Ten;Self. VIEWSHADOWBG. Layer. BorderWidth=1;Self. VIEWSHADOWBG. Layer. BorderColor= [Uicolor Graycolor]. Cgcolor;Self. VIEWSHADOWBG. Layer. Cornerradius=5;
Scenario Two: Custom View shadow Effect

To customize the view shadow, we use this property: We are using view.layer.shadowPath this property to customize the View shadow.

Bezier curve

Here we also use the Bezier curve, mathematical way to describe the graphic effect, common in the computer image description. The Bezier curve is described by Uibezierpath in Objective-c. Bézier curve knowledge points supplement:
Introduction to Bezier Curves
Bezier Curve-Wikipedia

To achieve a normal rectangular effect:
UIView *view = [[UIView alloc] init];View. Frame= CGRectMake ( -, -, -, -);View. Center= Self. View. Center;View. BackgroundColor= [Uicolor Clearcolor];View. Layer. Shadowcolor= [Uicolor Blackcolor]. Cgcolor;View. Layer. Shadowopacity=0.7F;View. Layer. Shadowoffset= Cgsizemake (30.0F10.0F;View. Layer. Shadowradius=2.0F;View. Layer. Maskstobounds= NO;normal rectangle Uibezierpath *path = [Uibezierpath bezierpathwithrect:view. Bounds];View. Layer. Shadowpath= Path. Cgpath;[Self. ViewAddsubview:view];
To implement a custom picture ladder:
UIView *view = [[UIView alloc] init];View. Frame= CGRectMake ( -, -, -, -);View. Center= Self. View. Center;View. BackgroundColor= [Uicolor Clearcolor];View. Layer. Shadowcolor= [Uicolor Blackcolor]. Cgcolor;View. Layer. Shadowopacity=0.7F;View. Layer. Shadowoffset= Cgsizemake (30.0F10.0F;View. Layer. Shadowradius=2.0F;View. Layer. Maskstobounds= NO;Custom Draw trapezoid cgsize size = view. Bounds. Size;Uibezierpath *path = [Uibezierpath Bezierpath];[Path Movetopoint:cgpointmake (size. Width*0.33F, size. Height*0.66f)];[Path Addlinetopoint:cgpointmake (size. Width*0.66F, size. Height*0.66f)];[Path Addlinetopoint:cgpointmake (size. Width*1.15F, size. Height*1.15f)];[Path Addlinetopoint:cgpointmake (size. Width* -0.15F, size. Height*1.15f)];View. Layer. Shadowpath= Path. Cgpath;[Self. ViewAddsubview:view];
To implement a custom size ellipse:
UIView *view = [[UIView alloc] init];View. Frame= CGRectMake ( -, -, -, -);View. Center= Self. View. Center;View. BackgroundColor= [Uicolor Clearcolor];View. Layer. Shadowcolor= [Uicolor Blackcolor]. Cgcolor;View. Layer. Shadowopacity=0.7F;View. Layer. Shadowoffset= Cgsizemake (30.0F10.0F;View. Layer. Shadowradius=2.0F;View. Layer. Maskstobounds= NO;Custom size Oval CGRect Ovalrect = CGRectMake (0,0, -, -);Uibezierpath *path = [Uibezierpath Bezierpathwithovalinrect:ovalrect];View. Layer. Shadowpath= Path. Cgpath;[Self. ViewAddsubview:view];

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ios--Adding a shadow to a view

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.