iOS Weibo the next day set the navigation bar properties, add the plus button

Source: Internet
Author: User
Tags set background

Point: 1, add the plus button at the bottom 2, set the navigation bar properties

1, Weibo the bottom of the button four of the buttons are the same, where the middle of the plus need to do a different processing

TableBar is defined by itself, the code is as follows

-(void) Viewwillappear: (BOOL) animated{    [Super viewwillappear:animated];        Delete the system automatically generated Uitabbarbutton for    (UIView *child in self.tabBar.subviews) {        if ([Child Iskindofclass:[uicontrol Class]]) {            [child removefromsuperview];}}    } /** *  initialize Tabbar */-(void) setuptabbar{    iwtabbar *customtabbar = [[Iwtabbar alloc] init];    Customtabbar.frame = self.tabBar.bounds;    Customtabbar.delegate = self;    [Self.tabbar Addsubview:customtabbar];    Self.customtabbar = Customtabbar;}

[Self.customtabbar AddTabBarButtonWithItem:childVc.tabBarItem];


Idea: When initializing, add it to the Iwtabbar, center it, and then add the other

Iwtabbar

-(ID) initWithFrame: (cgrect) frame{self = [super Initwithframe:frame]; if (self) {if (!IOS7) {//Non iOS7, set tabbar background self.backgroundcolor = [Uicolor colorwithpatternimage:[ui        Image imagewithname:@ "Tabbar_background"];        }//Add a plus button UIButton *plusbutton = [UIButton buttonwithtype:uibuttontypecustom];        [Plusbutton setbackgroundimage:[uiimage imagewithname:@ "Tabbar_compose_button"] forstate:uicontrolstatenormal]; [Plusbutton setbackgroundimage:[uiimage imagewithname:@ "tabbar_compose_button_highlighted"] forState:        Uicontrolstatehighlighted];        [Plusbutton setimage:[uiimage imagewithname:@ "Tabbar_compose_icon_add"] forstate:uicontrolstatenormal]; [Plusbutton setimage:[uiimage imagewithname:@ "tabbar_compose_icon_add_highlighted"] forState:        Uicontrolstatehighlighted]; Plusbutton.bounds = CGRectMake (0, 0, PlusButton.currentBackgroundImage.size.width,        PlusButton.currentBackgroundImage.size.height); [SelfAddsubview:plusbutton];    Self.plusbutton = Plusbutton; } return self;}
When the Add bar items is layoutsubviews, the position is recalculated,
-(void) layoutsubviews{    [Super layoutsubviews];        Adjust the position of the plus button    cgfloat h = self.frame.size.height;    CGFloat w = self.frame.size.width;    Self.plusButton.center = Cgpointmake (w * 0.5, H * 0.5);        The frame data of the button    cgfloat buttonh = h;    CGFloat buttonw = W/self.subviews.count;    CGFloat buttony = 0;        for (int index = 0; index<self.tabbarbuttons.count; index++) {        //1. Remove the button        Iwtabbarbutton *button = Self.tabba Rbuttons[index];                2. Set the button frame        cgfloat buttonx = index * BUTTONW;        if (Index > 1) {            Buttonx + = buttonw;        }        Button.frame = CGRectMake (Buttonx, Buttony, Buttonw, buttonh);                3. Bind tag        button.tag = index;}    }

2. Set Navigation Bar Properties

Content includes: Navigation bar Text properties, Rightitem properties, Pushviewcontroller

Idea: Set the navigation bar can not be divided into a set, packaged into a class, so that the class to manage all the properties

How to summarize into a class?

2. Package a navigation controller    iwnavigationcontroller *nav = [[Iwnavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:CHILDVC] ;    [Self addchildviewcontroller:nav];

iwnavigationcontroller.m//itcastweibo////Created by Apple on 14-5-6.//Copyright (c) 2014 itcast. All rights reserved.//#import "IWNavigationController.h" @interface Iwnavigationcontroller () @end @implementation        iwnavigationcontroller/** * The first time you use this class will be called (1 classes will only be called 1 times) */+ (void) initialize{//1. Set the navigation bar theme [self setupnavbartheme]; 2. Set the navigation bar button theme [self Setupbarbuttonitemtheme];}        /** * Set navigation bar button theme */+ (void) setupbarbuttonitemtheme{uibarbuttonitem *item = [Uibarbuttonitem appearance]; Set background if (!IOS7) {[Item setbackgroundimage:[uiimage imagewithname:@ "Navigationbar_button_background"] ForStat        E:uicontrolstatenormal Barmetrics:uibarmetricsdefault]; [Item setbackgroundimage:[uiimage imagewithname:@ "Navigationbar_button_background_pushed"] forState:        Uicontrolstatehighlighted Barmetrics:uibarmetricsdefault]; [Item setbackgroundimage:[uiimage imagewithname:@ "Navigationbar_button_background_disable"] forState: Uicontrolstatedisabled BarmetricS:uibarmetricsdefault];    }//Set Text property nsmutabledictionary *textattrs = [Nsmutabledictionary dictionary]; Textattrs[uitextattributetextcolor] = iOS7?    [Uicolor Orangecolor]: [Uicolor Graycolor];    Textattrs[uitextattributetextshadowoffset] = [Nsvalue Valuewithuioffset:uioffsetzero];    Textattrs[uitextattributefont] = [Uifont systemfontofsize:ios7? 14:12];    [item Settitletextattributes:textattrs Forstate:uicontrolstatenormal]; [item Settitletextattributes:textattrs forstate:uicontrolstatehighlighted];}         /** * Set navigation bar theme */+ (void) setupnavbartheme{//Remove appearance object Uinavigationbar *navbar = [Uinavigationbar appearance]; Set background if (!IOS7) {[NavBar setbackgroundimage:[uiimage imagewithname:@ ' navigationbar_background '] Forb        Armetrics:uibarmetricsdefault];    [UIApplication sharedapplication].statusbarstyle = Uistatusbarstyleblackopaque;    }//Set Caption Property nsmutabledictionary *textattrs = [Nsmutabledictionary dictionary]; Textattrs[uiTextattributetextcolor] = [Uicolor blackcolor];    Textattrs[uitextattributetextshadowoffset] = [Nsvalue Valuewithuioffset:uioffsetzero];    Textattrs[uitextattributefont] = [Uifont boldsystemfontofsize:19]; [NavBar settitletextattributes:textattrs];} -(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated{if (    Self.viewControllers.count > 0) {viewcontroller.hidesbottombarwhenpushed = YES; } [Super Pushviewcontroller:viewcontroller animated:animated];} @end



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.