iOS navigation bar (Customize and use System mode)

Source: Internet
Author: User

System mode:

    1. Set the navigation bar background image [Self.navigationController.navigationBar Setbackgroundimage:[[uiimage alloc] init] Forbarmetrics:uiba    Rmetricsdefault];        Self.navigationController.navigationBar.shadowImage = [[UIImage alloc]init];    [Self Navigationcontroller] setnavigationbarhidden:no Animated:yes]; Self.navigationController.navigationBar.backgroundColor = [[Uicolor alloc] initwithred:248/255.0 green:248/255.0        blue:248/255.0 alpha:1.0];    2. The Cancel button on the left side of the navigation panel uibutton* CancelButton = [UIButton buttonwithtype:uibuttontyperoundedrect];        if (CancelButton! = nil) {[CancelButton Settitle:post_cancel_button forstate:uicontrolstatenormal];        [CancelButton setframe:cgrectmake (0, 0, width_screen/5.0, 44)]; [CancelButton Settitlecolor:[[uicolor alloc] initwithred:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:        UIControlStateNormal];        CancelButton.titleLabel.font = [Uifont systemfontofsize:16.0]; Cancelbutton.contenthorizontalalignment = UICOntrolcontenthorizontalalignmentleft; [CancelButton addtarget:self Action: @selector (Cancelbuttoneventtouchupinside) Forcontrolevents:uicontroleven                Ttouchupinside];        Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] Initwithcustomview:cancelbutton];        if (leftitem! = nil) {Self.navigationItem.leftBarButtonItem = Leftitem;    }}//3. The Publish button to the right of the navigation panel uibutton* Postbutton = [UIButton buttonwithtype:uibuttontyperoundedrect];        if (Postbutton! = nil) {[Postbutton setframe:cgrectmake (0, 0, width_screen/5.0, 44)];        [Postbutton settitle:@ "release" Forstate:uicontrolstatenormal]; [Postbutton Settitlecolor:[[uicolor alloc] initwithred:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:        UIControlStateNormal];        PostButton.titleLabel.font = [Uifont systemfontofsize:16.0];        Postbutton.contenthorizontalalignment = Uicontrolcontenthorizontalalignmentright; [Postbutton Addtarget:seLF Action: @selector (Postbuttoneventtouchupinside) forcontrolevents:uicontroleventtouchupinside];        Uibarbuttonitem *rightitem = [[Uibarbuttonitem alloc] Initwithcustomview:postbutton];        if (rightitem! = nil) {Self.navigationItem.rightBarButtonItem = Rightitem;    }}//4. The middle text of the navigation panel uilabel* navigationlabel = [[UILabel alloc] Initwithframe:cgrectmake (0, 0, 0, 44)];        if (Navigationlabel! = nil) {[Navigationlabel settextcolor:[uicolor blackcolor]];        Navigationlabel.text = Post_navigation_title;        [Navigationlabel Settextalignment:nstextalignmentcenter];        Navigationlabel.font = [Uifont systemfontofsize:18.0];    Self.navigationItem.titleView = Navigationlabel;    }//5. Navigate to one of the split lines below uiview* line = [[UIView alloc]initwithframe:cgrectmake (0, + 44,width_screen, 1)]; if (line! = nil) {line.backgroundcolor = [[Uicolor alloc] initwithred:221/255.0 green:221/255.0 blue:221/255.0 Alpha: 1.0];    [Self.view Addsubview:line]; }

Custom:

    1. Create a navigation bar view UIView *navview = [[UIView alloc]initwithframe:cgrectmake (0, 0, Width_screen, 65)]; if (Navview! = nil)//When the Navigation view is not loaded successfully, the method {//1 is introduced. Set the background for the navigation view Navview.backgroundcolor = [Uicolor colorwithred:        248/255.0 green:248/255.0 blue:248/255.0 alpha:1];                [Self Navigationcontroller] setnavigationbarhidden:yes Animated:yes];        2. The Cancel button on the left side of the navigation panel uibutton* LeftButton = [UIButton buttonwithtype:uibuttontyperoundedrect];            if (LeftButton! = nil) {leftbutton.frame = CGRectMake (15, 20, 65, 44);            [LeftButton Settitle:post_cancel_button Forstate:uicontrolstatenormal]; [LeftButton Settitlecolor:[[uicolor alloc] initwithred:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:            UIControlStateNormal];            LeftButton.titleLabel.font = [Uifont systemfontofsize:16.0];            Leftbutton.contenthorizontalalignment = Uicontrolcontenthorizontalalignmentleft; [LeftButton AddTArget:self Action: @selector (Cancelbuttoneventtouchupinside) forcontrolevents:uicontroleventtouchupinside];        [Navview Addsubview:leftbutton];        //3. The Publish button to the right of the navigation panel uibutton* Rightbutton = [UIButton buttonwithtype:uibuttontyperoundedrect];            if (Rightbutton! = nil) {[Rightbutton setframe:cgrectmake (width_screen-80, 20, 65, 44)];            [Rightbutton settitle:@ "release" Forstate:uicontrolstatenormal]; [Rightbutton Settitlecolor:[[uicolor alloc] initwithred:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:            UIControlStateNormal];            RightButton.titleLabel.font = [Uifont systemfontofsize:16.0];            Rightbutton.contenthorizontalalignment = Uicontrolcontenthorizontalalignmentright; [Rightbutton addtarget:self Action: @selector (Postbuttoneventtouchupinside) Forcontrolevents:uicontroleven            Ttouchupinside];        [Navview Addsubview:rightbutton];       }         4. Navigation panel middle text uilabel* navtitle = [[UILabel alloc] Initwithframe:cgrectmake (+, width_screen-80-80,        44)];            if (navtitle! = nil) {[Navtitle settextcolor:[uicolor blackcolor]];            Navtitle.text = Post_navigation_title;            [Navtitle Settextalignment:nstextalignmentcenter];            Navtitle.font = [Uifont systemfontofsize:18.0];        [Navview Addsubview:navtitle];        }//5. Add a split line at the bottom of the Navigation view UIView *navdividingline = [[UIView alloc] init];            if (navdividingline! = nil) {navdividingline.frame = CGRectMake (0, + width_screen, 1);            Navdividingline.backgroundcolor = [Uicolor colorwithred:221/255.0 green:221/255.0 blue:221/255.0 alpha:1];        [Navview Addsubview:navdividingline];    }//6. Add navigation bar to view [Self.view Addsubview:navview]; }


iOS navigation bar (Customize and use System mode)

Related Article

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.