Custom NavgationBa return button

Source: Internet
Author: User


On iOS, The UINavigationController view can push many views without restrictions in the current view. However, some of the push buttons that come with them are not beautiful enough, and when the title of the previous page is very long, the return button is very long. How do I define a return button? Like the third image...


650) this. width = 650; "src =" http://img.blog.csdn.net/20130816204840687 "_ xhe_src =" http://img.blog.csdn.net/20130816204840687 "style =" max-width: 98%; "/> 650) this. width = 650; "src =" http://img.blog.csdn.net/20130816210121328 "_ xhe_src =" http://img.blog.csdn.net/20130816210121328 "style =" max-width: 98%; "/>


650) this. width = 650; "src =" http://img.blog.csdn.net/20130816204845000 "_ xhe_src =" http://img.blog.csdn.net/20130816204845000 "style =" max-width: 98%; "/>

Define an event in the view to be pushed


-(IBAction) pushVC :( id) sender {NavViewController * navVC = (NavViewController *) [self. storyboard instantiateViewControllerWithIdentifier: @ "NavViewController"]; navVC. title = NSLocalizedString (@ "set", nil); [self. navigationController pushViewController: navVC animated: YES];}



Replace the return button and define the Custom button


- (void)viewDidLoad{    [super viewDidLoad];            UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];    backBtn.frame = CGRectMake(0, 0, 44, 44);            [backBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];            UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];    self.navigationItem.leftBarButtonItem = backItem;             // Do any additional setup after loading the view.}-(void)doBack:(id)sender{    [self.navigationController popViewControllerAnimated:YES];}



Source code: https://github.com/XFZLDXF/XFNavBarBtn



This article from the "fresh wind wave" blog, please be sure to keep this source http://duxinfeng.blog.51cto.com/3911492/1279119

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.