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