ios - multiple shadowOffset on UIViewController -


i've looked on web results consist of "how shadowoffset." need apply "shadow,border, , cornerradius" multiple objects in views. wanted see if theres more effienct way? or if theres way keep more organized. heres of code. keep in mind have multiple views this, amount of space code takes gets pretty annoying.

topview.layer.cornerradius = 3; topview.layer.maskstobounds = yes; topview.layer.bordercolor= [uicolor lightgraycolor].cgcolor; topview.layer.borderwidth = 0.5f;  bottomview.layer.cornerradius = 3; bottomview.layer.maskstobounds = yes; bottomview.layer.bordercolor= [uicolor lightgraycolor].cgcolor; bottomview.layer.borderwidth = 0.5f;  eventname.layer.maskstobounds = no; eventname.layer.shadowcolor = [uicolor blackcolor].cgcolor; eventname.layer.shadowopacity = 0.5; eventname.layer.shadowradius = 2; //(right,down) (-right,-down) eventname.layer.shadowoffset = cgsizemake(0.0f, 0.8f);  addresslabel.layer.maskstobounds = no; addresslabel.layer.shadowcolor = [uicolor blackcolor].cgcolor; addresslabel.layer.shadowopacity = 0.5; addresslabel.layer.shadowradius = 2; //(right,down) (-right,-down) addresslabel.layer.shadowoffset = cgsizemake(0.0f, 0.8f);  datelabel.layer.maskstobounds = no; datelabel.layer.shadowcolor = [uicolor blackcolor].cgcolor; datelabel.layer.shadowopacity = 0.5; datelabel.layer.shadowradius = 2; //(right,down) (-right,-down) datelabel.layer.shadowoffset = cgsizemake(0.0f, 0.8f);  typelabel.layer.maskstobounds = no; typelabel.layer.shadowcolor = [uicolor blackcolor].cgcolor; typelabel.layer.shadowopacity = 0.5; typelabel.layer.shadowradius = 2; //(right,down) (-right,-down) typelabel.layer.shadowoffset = cgsizemake(0.0f, 0.8f);  eventcaption.layer.maskstobounds = no; eventcaption.layer.shadowcolor = [uicolor blackcolor].cgcolor; eventcaption.layer.shadowopacity = 0.5; eventcaption.layer.shadowradius = 2; //(right,down) (-right,-down) eventcaption.layer.shadowoffset = cgsizemake(0.0f, 0.8f); 

if of shadows identical, choose loop on array (or set, since don't care order of items applied to) of views apply same shadow ? is, see 2 kind of shadows in code pasted here, lightgray , black. :

nsarray * blackshadowitems = @[eventname, addresslabel, datelabel]; (uiview * view in blackshadowitems) {     view.layer.maskstobounds = no;     view.layer.shadowcolor = [uicolor blackcolor].cgcolor;     view.layer.shadowopacity = 0.5;     view.layer.shadowradius = 2;     //(right,down) (-right,-down)     view.layer.shadowoffset = cgsizemake(0.0f, 0.8f); } 

or declare function :

- (void)setblackshadow:(uiview *)view {     view.layer.maskstobounds = no;     view.layer.shadowcolor = [uicolor blackcolor].cgcolor;     view.layer.shadowopacity = 0.5;     view.layer.shadowradius = 2;     //(right,down) (-right,-down)     view.layer.shadowoffset = cgsizemake(0.0f, 0.8f); } 

you can combine both of these solutions.

finally, note if these views declared in .xib file, declare iboutletcollection regroup views according type of shadow want set on it. quite similar declaring nsarray or nsset yourself.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -