ios - how to set image on default back button of navigation bar -
i setting button image on navigation bar view controllers using following code in appdelegate:
[[uibarbuttonitem appearance] setbackbuttonbackgroundimage:image forstate:uicontrolstatenormal barmetrics:uibarmetricsdefault];
now in 1 of view controllers pick newimage gallery , save it. want save newimage, 'image' of button gets replaced 'newimage'.
i tried following code in viewwillappear of each , every view controller
[self.navigationitem.backbarbuttonitem setbackbuttonbackgroundimage:newimage forstate:uicontrolstatenormal barmetrics:uibarmetricsdefault];
and tried
[self.navigationitem.backbarbuttonitem setimage:new];
this too. in vain. image gets changed when run app again , when code in appdelegate gets called.
plz help!
for set own image button need set custom appearance . , call in appdelegate.h file.
note: need set once in appdelegate.h
, apply in whole project. don't need declare in each , every controller.
please check this.
//in appdelegate.h file - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { [self customappearance]; //method declaration }
and declare image image name in custom appearance. this,
-(void)customappearance { //int imagesize = 20; uiimage *myimage = [uiimage imagenamed:@"icon_back"]; //set backbutton imagename uiimage *backbuttonimage = [myimage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; // use new backbuttomimage [[uinavigationbar appearance] setbackindicatorimage:backbuttonimage]; [[uinavigationbar appearance] setbackindicatortransitionmaskimage:backbuttonimage]; /* uiimage *backbutton=[[uiimage imagenamed:@"icon_back"]resizableimagewithcapinsets:uiedgeinsetsmake(0, 0, 0, 0) resizingmode:uiimageresizingmodestretch]; //resizableimagewithcapinsets:uiedgeinsetsmake(0, 0, 0, 0) resizingmode:uiimageresizingmodestretch]; [[uibarbuttonitem appearance] setbackbuttonbackgroundimage:backbutton forstate:uicontrolstatenormal barmetrics:uibarmetricsdefault];*/ [[uibarbuttonitem appearance] setbackbuttontitlepositionadjustment:uioffsetmake(-400.f, 0) forbarmetrics:uibarmetricsdefault]; }
and navigationbar button this.
Comments
Post a Comment