iphone - iOS App view and navigation design custom class -


in ios app have below code snipped repeating on , on again in every class.

i have tried cast method nsobject class receive errors use of "navigationitem".

-(void)customdesign { //background pattern self.view.backgroundcolor = [[uicolor alloc] initwithpatternimage:[uiimage imagenamed:@"bg-pattern.png"]];  // nav bar [self.navigationcontroller.navigationbar setbackgroundimage:[uiimage imagenamed:@"top_bar.png"] forbarmetrics:uibarmetricsdefault];  //back button color  #2974c3 [self.navigationcontroller.navigationbar settintcolor:[uicolor colorwithred:41.0/255.0f green:116.0/255.0f blue:195.0/255.0f alpha:1.0]];  //settings button uiimage* settingsimage = [uiimage imagenamed:@"buttonmenu.png"]; cgrect frameimg = cgrectmake(0, 0, settingsimage.size.width, settingsimage.size.height); uibutton *uisettingsbutton = [[uibutton alloc] initwithframe:frameimg]; [uisettingsbutton setbackgroundimage:settingsimage forstate:uicontrolstatenormal]; [uisettingsbutton addtarget:self action:@selector(menubutton) forcontrolevents:uicontroleventtouchupinside]; [uisettingsbutton setshowstouchwhenhighlighted:yes]; //add buton navbar uibarbuttonitem *settingsbutton = [[uibarbuttonitem alloc] initwithcustomview:uisettingsbutton]; self.navigationitem.leftbarbuttonitem = settingsbutton; 

}

you should creating own subclass of uiviewcontroller or uitableviewcontroller (whichever you're using) , place code in viewdidload method of subclass. controllers need code can extend custom class. save hassle of having write code everywhere.

your custom subclass:

@interface customviewcontroller : uiviewcontroller  @end 

your viewdidload method in subclass:

@implementation customviewcontroller     - (void)viewdidload {         [super viewdidload];          // custom code here...     } @end 

extend custom class controllers want have common stuff done in:

@interface visuallychangedviewcontroller : customviewcontroller  @end  @implementation visuallychangedviewcontroller     - (void)viewdidload {         [super viewdidload];     } @end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -