Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Customized back button

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 420
    Comment on it

    The default back button in the navigation bar that pops the current view and takes the screen to the previous ViewController, can be easily customized and made to look fancy, trendy and in relation with the rest of the theme of the app.

    This is pretty easy to do using a little bit of code.

    • Just add a UIButton, with buttonType custom.
    • Set the image for the custom button.
    • Add target for the button and set its frame in the ViewController.

    Then create a UIBarbuttonItem with a custom view and set the custom button as the UIBarButtonItem.

    The required code for performing this customization is given below.

      UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
        [back setImage:[UIImage imageNamed:@"back_btn@2x.png"] forState:UIControlStateNormal];
        [back addTarget:self action:@selector(backButtonTapped) forControlEvents:UIControlEventTouchUpInside];
        back.showsTouchWhenHighlighted = YES;
        [back setFrame:CGRectMake(0, 0,20, 30)];
        UIBarButtonItem *barbutton1 = [[UIBarButtonItem alloc]initWithCustomView:back];
        self.navigationItem.leftBarButtonItem = barbutton1;
    

    The only problem with customizing the back button in the navigation bar is that the default back button appears by itself and works without any code written by the developer. But in case of the customized back button the developer have to code the working of the button as well.

    Therefore the code to make the customized back button work as normal is as follows:

    -(void)backButtonTapped
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: