Tuesday, October 28, 2014

Create custom navigation bar back button

//**************************************************************************
//Method    : createLeftNavigationButton
//Params    : create the left navigation back button with the image
//Return    :
//**************************************************************************

#define IMAGE(imageName)    (UIImage *)[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName         ofType:IMAGE_TYPE_PNG]]

- (void)createLeftNavigationButton {
    
    //customize right bar button item
    UIView *backButtonView = [[UIView alloc] initWithFrame:NAVIGATION_BAR_BUTTON_RECT];

    [backButtonView setBackgroundColor:[UIColor clearColor]];
    
    UIButton *backButton = [[UIButton alloc] init];
    backButton.frame     = backButtonView.frame;

    [backButton addTarget:self action:@selector(backButtonClick:) 
         forControlEvents:UIControlEventTouchUpInside];

    [backButton setImage:IMAGE(@"backButton") forState:UIControlStateNormal];    
    [backButtonView addSubview:backButton];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]  
                                  initWithCustomView:backButtonView];    

}

No comments:

Post a Comment