1 //2 //RQHTABBARCONTROLLER.M3 //Tabbarview4 //5 //Created by Apple on 15-1-13.6 //Copyright (c) 2015 __mycompanyname__. All rights reserved.7 //You can have this class associated with storyboard, which inherits Uitabbarcontroller8 9 #import "RQHTabBarController.h"Ten One @implementationRqhtabbarcontroller A @synthesizeselectedbtn;//can also be written with a bool value to take the inverse - -- (void) Viewdidload the { - -CGRect rect = self.tabBar.frame;//get the size of Tabbar. -[Self.tabbar Removefromsuperview];//Remove the Tabbar of the system + - //Create a view to replace the Tabbar location +UIView *myview = [UIViewNew]; AMyview.frame = CGRectMake (0, rect.origin.y- -, Rect.size.width, rect.size.height+ -); at [Self.view Addsubview:myview]; - -Uiimageview *background =[[Uiimageview alloc]initwithframe:myview.bounds]; -Background.image = [UIImage imagenamed:@"Backgroundtabbar"]; - [MyView Addsubview:background]; - in for(intI=0; i<3; i++) { -UIButton *btn = [UIButtonNew]; toNSString *imagename = [NSString stringWithFormat:@"tabbar%d", i +1]; +NSString *imagenamesel = [NSString stringWithFormat:@"Tabbar%dsel", i +1]; - the [btn setimage:[uiimage imagenamed:imagename] forstate:uicontrolstatenormal]; * [btn setimage:[uiimage Imagenamed:imagenamesel] forstate:uicontrolstateselected]; $CGFloat x = i * myView.frame.size.width/5; Panax NotoginsengBtn.frame = CGRectMake (x,0, MyView.frame.size.width/5, myview.frame.size.height+Ten); - the [MyView addsubview:btn]; + ABtn.tag = i;//set the tag of the button to easily index the current button and jump to the corresponding view the + //The listening method with parameters remember to add "colon" - [btn addtarget:self Action: @selector (CLICKBTN:) forcontrolevents:uicontroleventtouchupinside]; $ $ //The first button is selected when the setting is just entered - if(0==i) { -btn.selected =YES; theSELF.SELECTEDBTN = BTN;//Set this button as the selected button - } Wuyi the } - Wu - } About $- (void) CLICKBTN: (UIButton *) button { - //1. First set the previously selected button to unchecked -self.selectedBtn.selected =NO; - //2. Then set the current button to selected Abutton.selected =YES; + //3. Finally assign the current button to the previously selected button theSELF.SELECTEDBTN =button; - $ //4. Jump to the corresponding view controller. (using the Selectindex parameter to set the selected controller) theSelf.selectedindex =Button.tag; the } the the @end
----------------------------------------
I miss the one that I can't go back to
----------------------------------------
ios-Custom Tabbar