ios7+ Custom Back button

Source: Internet
Author: User

Originally I used to create UIButton assignment to Self.navigationItem.leftBarButtonItem the way to set the return button, with a feel quite normal, the results of the "Frog cow" in the article "Java to ios-the first project summary (2)", A major problem has been found: The gesture return function is gone because the ability to customize the return button with the Leftbarbuttonitem setting will cause the gesture return to fail.

If I do not customize the return button, and because I am using rdvtabbarcontroller, I need to manually set the Hide Tabbar property in the return method, so I need to intercept the triggering method of the return gesture, remembering that the story is big.

Groping for half a day, found a simple custom return button and retain the ability to return gestures, the way to optimize the hide Tabbar can not be intercepted. Define a Isshowtabbar in Baseviewcontroller, default to No, set isshowtabbar=yes in the Init or Initwithnibname method of a first-level page, Other Viewcontroller do not move, Baseviewcontroller rewrite the following method:

-(void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated]; if (Self.rdv_tabBarController.isTabBarHidden = = Isshowtabbar) {[Self.rdv_tabbarcontroller settabbarhidden:!isshowt    Abbar]; }}

Customize the return button code without text as follows: (code from custom iOS7 navigation bar background, title and Back button text color)

Custom return button UIImage *backbuttonimage = [[UIImage imagenamed:@ "Fanhui.png"] resizableimagewithcapinsets:  Uiedgeinsetsmake (0, 30, 0, 0)]; [[Uibarbuttonitem appearance] Setbackbuttonbackgroundimage:backbuttonimage forstate:uicontrolstatenormal  Barmetrics:uibarmetricsdefault]; The text position setting for the return button is not displayed on the screen [[Uibarbuttonitem appearance] Setbackbuttontitlepositionadjustment:uioffsetmake ( Nsintegermin, Nsintegermin) Forbarmetrics:uibarmetricsdefault];

The display results are as follows:



ios7+ Custom Back button

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.