Cat Learning iOS Weibo project Combat (4) Weibo custom Tabbar middle Add button

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243

One:

Custom Tabbar implements the bottom middle of the Add button

Second: Ideas

First of all in their own Tabbarcontroller the system Tabbar set to their own Tabbar (Nytabbar), here because the Tabbar property is ReadOnly, so we have to use KVC or message management to set his

Then write your own nytabbar. This will first go through all the view on the current Tabbar, if it is Uitabbarbutton, take out to reset their position, and re-assign the value, the next is to empty the middle of the added position, and then put the Add button up, OK.

Three: Code calls

The first is how to call the code

    //自定义tabBar    NYTabBar *tabBar = [[NYTabBar alloc]initWithFrame:self.tabBar.frame];    //用kvc把readly的tabBar属性改成自定义的    [self setValue:tabBar forKey:@"tabBar"];
Nytabbar.m

The NYTabBar.h file won't be written, there's nothing in it.

NYTABBAR.M:

////NYTABBAR.M//Cat Weibo////Created by Apple on 15-7-24.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYTabBar.h"  @interface nytabbar()/** * Add an increase button * /@property(nonatomic,Weak)UIButton*addbutton;@end @implementation nytabbar -(UIButton*) addbutton{if(_addbutton = =Nil) {UIButton*BTN = [UIButtonButtonwithtype:uibuttontypecustom]; [Btn setimage:[UIImageimagenamed:@"Tabbar_compose_icon_add"] Forstate:uicontrolstatenormal]; [Btn setbackgroundimage:[UIImageimagenamed:@"Tabbar_compose_button"] Forstate:uicontrolstatenormal]; [Btn setimage:[UIImageimagenamed:@"tabbar_compose_icon_add_highlighted"] forstate:uicontrolstatehighlighted]; [Btn setbackgroundimage:[UIImageimagenamed:@"tabbar_compose_button_highlighted"] forstate:uicontrolstatehighlighted]; _addbutton = BTN;the size of the button is as large as the background image.[Btn SizeToFit]; [ SelfAddsubview:_addbutton]; }return_addbutton;}//Adjust the location of the sub-space-(void) layoutsubviews{[SuperLayoutsubviews];CGFloatW = Self. Bounds. Size. Width;CGFloath = Self. Bounds. Size. Height;CGFloatBtnx =0;CGFloatBtny =0;CGFloatBTNW = w/5;CGFloatBTNH = h;inti =0;//1, traversing all the view on the current Tabbar     for(UIView*tabbarbtn in Self. Subviews) {//2, if it's Uitabbarbutton, take it out and reset their position.        if([Tabbarbtn iskindofclass:nsclassfromstring (@"Uitabbarbutton")] {btnx = i * BTNW; Tabbarbtn. Frame= CGRectMake (Btnx, Btny, BTNW, BTNH);//When it comes to the second time, add a location to cephalostachyum the position of the button.             if(i==1) {i++;        } i++; }    }//Set the location of the Add button     Self. AddButton. Center= Cgpointmake (W *0.5, H *0.5);}@end
IV: Supplement

You can also use message management when calling

    //自定义tabBar    NYTabBar *tabBar = [[NYTabBar alloc]initWithFrame:self.tabBar.frame];        /*这个地方还有一种用消息管理设置的,这样也可以,使用个步骤是     1:先导入头文件#import <objc/message.h>     2:到项目中Build Settings中查找msg ,然后把yes改成no     3:代码写objc_msgSend调用就行了        注意:这样的方法框架中比较多,目的为了不让人看懂,还有显得c牛逼,——————没啥鸟用。。     */     //用消息管理设置   objc_msgSend(self@selector(setTabBar:),tabBar);

Steps:
1: First Import header file

#import <objc/message.h>

2: Find msg in the project build settings, then change Yes to No

3: Code write Objc_msgsend call on the line
Note: This method is more in the framework, the purpose in order not to let people understand, there is a C, —————— no bird use.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Cat Learning iOS Weibo project Combat (4) Weibo custom Tabbar middle Add 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.