ios - Navigation Styling throughout app -
is there way implement below code styling of navigation bar in viewdidload or globally somehow, instead of pasting in every vc? thanks.
// navagation styling viewcontroller.title = @"nav title"; [viewcontroller.navigationcontroller.navigationbar settitletextattributes:[nsdictionary dictionarywithobjectsandkeys:[uifont fontwithname:@"gibson-light" size:20.0], nsfontattributename, nil]]; uibarbuttonitem *rightbarbutton = [[uibarbuttonitem alloc] initwithtitle:nil style:uibarbuttonitemstyleplain target:viewcontroller action:nil]; rightbarbutton.image = [uiimage imagenamed:@"settings_cog"]; rightbarbutton.tintcolor = [uicolor graycolor]; viewcontroller.navigationitem.rightbarbuttonitem = rightbarbutton;
you can create baseviewcontroller , put above code in , extend controllers baseviewcontroller.
do this:
create objective-c class baseviewcontroller.h , .m
in baseviewcontroller.h
@interface baseviewcontroller : uiviewcontroller { nsstring *_title; } - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil title:(nsstring *)navtitle; @end
in baseviewcontroller.m
@implementation baseviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil title:(nsstring *)navtitle { _title = navtitle; } - (void)viewdidload { self.title = _title; [self.navigationcontroller.navigationbar settitletextattributes:[nsdictionary dictionarywithobjectsandkeys:[uifont fontwithname:@"gibson-light" size:20.0], nsfontattributename, nil]]; uibarbuttonitem *rightbarbutton = [[uibarbuttonitem alloc] initwithtitle:nil style:uibarbuttonitemstyleplain target:viewcontroller action:nil]; rightbarbutton.image = [uiimage imagenamed:@"settings_cog"]; rightbarbutton.tintcolor = [uicolor graycolor]; self.navigationitem.rightbarbuttonitem = rightbarbutton; } @end
now can create view controller , extend baseviewcontroller instead if uiviewcontroller.
let me know if have questions.
Comments
Post a Comment