Some times we need to create a custom back button for Navigation Bar in iOS. If you want to create an easy navigational back button instead of creating a view and add that view in navigation bar then use below code to achieve it.
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:@"back.png"];
[backBtn setImage:backBtnImage forState:UIControlStateNormal];
backBtn.frame = CGRectMake(0, 0, 35, 40);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
self.navigationItem.leftBarButtonItem = backButton;
Above code will override default navigation back button with above customized button.
Happy Coding!!!
0 Comment(s)