1. Tag View Controller--Uitabbarcontroller
- View (UIView)---> Layers---> Sub-view
- View controller (Uiviewcontroller)---> Management view
- Navigation Controller (UINAVIGATIONCONTROLLER)---> Manage hierarchical View Controllers
- Tag View controller (Uitabbarcontroller)---> Manage view controllers without hierarchies
the inheritance relationship of 1> Uitabbarcontroller
@interface Uitabbarcontroller : Uiviewcontroller <uitabbardelegate, nscoding>
2> Uitabbarcontroller Three-storey structure
3> Code creation Uitabbarcontroller
In the Application:idfinishlaunchingwithoptions: method, create
① Create window (need to delete the main story version of the project)
Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; = [Uicolor whitecolor]; [Self.window makekeyandvisible];
② Creating Uitabbarcontroller objects
1Uitabbarcontroller *maintabbar =[[Uitabbarcontroller alloc] init];2 3 //To create a controller object4Uiviewcontroller *FIRSTVC =[[Uiviewcontroller alloc] init];5 6FirstVC.view.backgroundColor =[Uicolor Cyancolor];7 8 //Set Tabbaritem9 //first way: System styleTenFirstvc.tabbaritem = [[Uitabbaritem alloc] initwithtabbarsystemitem:uitabbarsystemitemfavorites tag: -]; One A //Second way: Custom styles -Uiviewcontroller *SECONDVC =[[Uiviewcontroller alloc] init]; - theSecondVC.view.backgroundColor =[Uicolor Redcolor]; - - //Create a picture -UIImage *secondimage = [UIImage imagenamed:@"cargary"]; + -UIImage *secondselectimage = [UIImage imagenamed:@"carred"]; + A #pragmaMark-Set the picture to preserve the original style atSecondimage =[Secondimage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; -Secondselectimage =[Secondselectimage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; - - #pragmaMark- -Secondvc.tabbaritem = [[Uitabbaritem alloc] Initwithtitle:@"second page"image:secondimage Selectedimage:secondselectimage]; - in //THIRDVC -Uiviewcontroller *THIRDVC =[[Uiviewcontroller alloc] init]; to +ThirdVC.view.backgroundColor =[Uicolor Purplecolor]; - theThirdvc.tabbaritem = [[Uitabbaritem alloc] Initwithtitle:@"found"Image:[uiimage imagenamed:@"Findgray"] Tag:101]; * $ //FOURTHVCPanax NotoginsengUiviewcontroller *FOURTHVC =[[Uiviewcontroller alloc] init]; - theFourthVC.view.backgroundColor =[Uicolor Greencolor]; + AFourthvc.tabbaritem = [[Uitabbaritem alloc] Initwithtitle:@"my own"Image:[uiimage imagenamed:@"Usergray"] Tag:102]; the + //FIFTHVC -Uiviewcontroller *FIFTHVC =[[Uiviewcontroller alloc] init]; $ $FifthVC.view.backgroundColor =[Uicolor Orangecolor]; - -Fifthvc.tabbaritem = [[Uitabbaritem alloc] initwithtabbarsystemitem:uitabbarsystemitemdownloads tag:103]; the - //SIXTHVCWuyiUiviewcontroller *SIXTHVC =[[Uiviewcontroller alloc] init]; the -SixthVC.view.backgroundColor =[Uicolor Magentacolor]; Wu -Sixthvc.tabbaritem = [[Uitabbaritem alloc] initwithtabbarsystemitem:uitabbarsystemitemhistory tag:104]; About $ //set the controller array -Maintabbar.viewcontrollers = @[firstvc, SECONDVC, THIRDVC];
③ Setting the Uitabbarcontroller object to the root View Controller of window
1 self.window.rootViewController = Maintabbar;
Important attributes of 4> Uitabbarcontroller
Viewcontrollers properties of the application 3>② code
// set the first selection when entering the app 1;
2. Uitabbar1> Overview
Uitabbar contains multiple uitabbaritem , each uitabbaritem a uiviewcontroller
The height of the Uitabbar is
The system displays up to 5 Uitabbaritem , and when uitabbaritem exceeds 5 , the system automatically adds a more button , Click the More button, the button that doesn't appear at the bottom will appear as a list
Properties of Uitabbar : tintcolor , bartintcolor , image settings , etc.
2> Uitabbar Common Properties
1 //properties of the Tabbar2 3 //Set the selected color4MainTabBar.tabBar.tintColor =[Uicolor Greencolor];5 6 //whether to turn on translucent effects7MainTabBar.tabBar.translucent =NO;8 9 //set the color of the TabbarTen //MainTabBar.tabBar.barTintColor = [Uicolor graycolor];
3> Uitabbaritem
// Setting hints @" there's news . ";
① System style
// first way: System style Firstvc.tabbaritem = [[Uitabbaritem alloc] initwithtabbarsystemitem:uitabbarsystemitemfavorites tag: ;
② Custom Styles
// second way: Custom style secondvc.tabbaritem = [[Uitabbaritem alloc] Initwithtitle:@ " second page " Image:secondimage Selectedimage:secondselectimage];
secondimage and secondselectimage are two variables of type UIImage
- Picture processing of Uitabbaritem
1 //Create a picture2UIImage *secondimage = [UIImage imagenamed:@"cargary"];3 4UIImage *secondselectimage = [UIImage imagenamed:@"carred"];5 6 #pragmaMark-Set the picture to preserve the original style7Secondimage =[Secondimage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];8Secondselectimage = [Secondselectimage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
3. Customizing the Tabbar appearance(uiappearance)
1> Overview
If you want to set all the navigation by a key to try the color of the controller, similar to the QQ one-touch skin operation, can be operated through the uiappearance protocol , through which some controls can be defined color, and so on.
2> Using code
1 //set the global appearance2 //set the appearance of the tabbar using [Uitabbar appearance] to get the currently applied Uitabbar object3 //Note: Setting the global appearance is best in appdelegate, otherwise it will not work4 [[Uitabbar appearance] Setbartintcolor:[uicolor Cyancolor]]; [[Uitabbar appearance] Settintcolor:[uicolor Browncolor]];5 //change the navigation bar appearance6 [[Uinavigationbar appearance] Setbartintcolor:[uicolor Lightgraycolor]];7 //Change the navigation bar font8[[Uinavigationbar appearance] Settitletextattributes: [nsdictionary dictionarywithobjectsandkeys:[uicolor RedColor] , Nsforegroundcolorattributename, [Uifont systemfontofsize: -], Nsfontattributename, nil]];
The Uitabbarcontroller of iOSDay28