Custom backButton in Navigation Bar


// Make Custom back button for Navigation Bar Using static metho



//In Project whenEver you want back button then write

self.navigationItem.leftBarButtonItem = [CommonFunctions getBackBtn]; 




//in CommonFunction.h write

//Method

+ (UIBarButtonItem *) getBackBtn;



//Action
+ (void)backBtnPressed;




//in CommonFunction.m write


+ (UIBarButtonItem *) getBackBtn{
    UIButton * backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0.0f,0.0f,50.0f,28.0f)];
    [backBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"BackBtn"]] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    return backBarButton;    
}

//Action For  - BackButton
+ (void)backBtnPressed{
    //AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
    UINavigationController *navController = (UINavigationController*)[[AppDelegate sharedAppDelegate] navigationController];
    [navController popViewControllerAnimated:YES];
}

Comments

Popular posts from this blog

Hacker Rank problem solution

How to Make REST api call in Objective-C.

Building and Running Python Scripts with Xcode