i know there 2 distinct ways customize uinavigationbar: can either set background image custom png, or customize bar's appearance in code, programmatically. if aim support ios 4,5,6 make sense try customize bar's appearance through code?
i want navigationbar without gradience, a solid color, rounded corners, , an extremely thin shadow line. post image below need @ least 10 reputation points :(
i've started following code address no gradience , solid color issues, , i've placed in .m file of rootviewcontroller before @implementation of class itself, no avail:
@implementation uinavigationbar (uinavigationbarcategory) - (void)drawrect:(cgrect)rect { uicolor *color = [uicolor bluecolor]; cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolor(context, cgcolorgetcomponents( [color cgcolor])); cgcontextfillrect(context, rect); } @end
i have implemented code round out corners, works:
calayer *capa = [self.navigationcontroller navigationbar].layer; [capa setshadowcolor: [[uicolor blackcolor] cgcolor]]; [capa setshadowopacity:0.85f]; [capa setshadowoffset: cgsizemake(0.0f, 1.5f)]; [capa setshadowradius:2.0f]; [capa setshouldrasterize:yes]; //round cgrect bounds = capa.bounds; bounds.size.height += 10.0f; //i'm reserving enough room shadow uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:bounds byroundingcorners:(uirectcornertopleft | uirectcornertopright) cornerradii:cgsizemake(10.0, 10.0)]; cashapelayer *masklayer = [cashapelayer layer]; masklayer.frame = bounds; masklayer.path = maskpath.cgpath; [capa addsublayer:masklayer]; capa.mask = masklayer;
any on matter appreciated!
if want target ios < 5 uiappearance
won't because supported ios >= 5.
so in opinion, using png
file navigation bar's background faster , maybe safer. depending on desired result can code , make faster, create baseviewcontroller
handle navigation bar's appearance (background, title, buttons etc) , custom view controllers can inherit baseviewcontroller
, implementation in cases can has it's own drawbacks since can't inherit multiple classes in ios, , i'm afraid find out little bit late when point when want have features view controller doesn't inherit baseviewcontroller
.
on other hand, creating color , graphics code raise issues beloved designers want 1px left/up/right/down/diagonal/etc, , in way have headaches (happen me).
if targeting ios >=5 uiappearance
friend.
so in conclusion, if targeting ios >= 5 use uiappearance
if not, if have more complex (gradient, lines, strange colors) ui nav bar use png
, if have simple (one flat color) ui nav bar, can code no problems.
Comments
Post a Comment