We often use Uitabbarcontroller to lay out apps in development, using Uitabbarcontroller to make the app look clearer, the iOS system's Alarm clock program, ipod programs are very good descriptions and Android's bottom navigation is very similar, the most famous of this layout than. Uitabbarcontroller can be applied to the main line clear, functional clear situation, at a glance, so that the app will want to show the data or the company's product sentiment better service and users, about the Uitabbar level map, you can refer to the official website to give pictures:
Page Layout
The best way to explain the knowledge points is the actual combat, first look at the results can be achieved:
The bottom of a row of navigation is tabbar, travel, bookmarks, messages, clocks belong to Tabbaritem, each tabbaritem can be set text and pictures, width is evenly divided, height fixed to 49, can be placed up to five item, general situation in order to beautiful place four, If more than five, there will be more than one more display bar.
Over five effects:
Demo Implementation
iOS effect is generally implemented in two, one is directly storyboard directly into a control, and then through the code settings, the other is directly pure code settings, two ways to see their personal preferences, Uitabbarcontroller is generally the main page of the program, If it is a pure code setting, it can be implemented in Appdelegate didfinishlaunchingwithoptions.
The code in Appdelegate is as follows:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {// Override point for customization after application launch. Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; Self.window.backgroundColor = [Uicolor Whitecolor]; Uitabbarcontroller *tabbarcontroller=[[uitabbarcontroller Alloc]init]; Airplaneviewcontroller *planeviewcontroller=[[airplaneviewcontroller Alloc]init]; [email protected] "travel"; Planeviewcontroller.tabbaritem.image=[uiimage imagenamed:@ "Airplane"]; Bookmarkviewcontroller *bookmarkcontroller=[[bookmarkviewcontroller Alloc]init]; [email protected] "bookmarks"; Bookmarkcontroller.tabbaritem.image=[uiimage imagenamed:@ "Bookmark"]; Chatviewcontroller *chatviewcontroller=[[chatviewcontroller Alloc]init]; [email protected] "message"; Chatviewcontroller.tabbaritem.image=[uiimage imagenamed:@ "Chat"]; Clockviewcontroller *clockviewcontrolLer=[[clockviewcontroller Alloc]init]; [email protected] "clock"; Clockviewcontroller.tabbaritem.image=[uiimage imagenamed:@ "Clock"]; [email protected] "25"; Uiviewcontroller *briefcontroller=[[uiviewcontroller Alloc]init]; [email protected] "purse"; Briefcontroller.tabbaritem.image=[uiimage imagenamed:@ "Breifcase"]; Uiviewcontroller *chestviewcontroller=[[uiviewcontroller alloc]init];//[email protected] "box";//ChestVie Wcontroller.tabbaritem.image=[uiimage imagenamed:@ "Breifcase"]; Nsarray *arrcontrollers=[nsarray Arraywithobjects:planeviewcontroller,bookmarkcontroller,chatviewcontroller, Clockviewcontroller,nil]; Tabbarcontroller.viewcontrollers=arrcontrollers; Set the root controller Self.window.rootviewcontroller=tabbarcontroller; Set window main form [Self.window makekeyandvisible]; return YES;}
code in airplaneviewcontroller :
-(void) viewdidload { [super viewdidload]; Do any additional setup after loading the view. UILabel *label=[[uilabel alloc]initwithframe:cgrectmake (0, ten, ())]; [Email protected] "blog Park: flyelephant\n blog Address: \nhttp://www.cnblogs.com/xiaofeixiang"; label.numberoflines=0; [Self.view Setbackgroundcolor:[uicolor Cyancolor]; [Self.view Addsubview:label];}
About the setup of code in Uitabbarcontroller the website gives a clear picture of logic, simple and easy to understand:
The viewcontrollers in Uitabcontroller is a collection of arrays, just set the corresponding data to the properties of Uitabbarcontroller, and the other is to manipulate each viewcontroller, Set the page layout and settings for each viewcontroller, and for the way you drag the controls, simply drag them into a tabbarcontroller, as follows, if you set the corresponding sub-controller:
A demo of the final effect of the demo:
Uitabbarcontroller only supports vertical screens by default, and when the device direction changes, it queries all viewcontroller contained in the viewcontrollers, only if all viewcontroller support that direction. Uitabbarcontroller only occurs when the rotation is not the default vertical. When Uitabbarcontroller supports rotation, and rotation occurs, only the currently displayed Viewcontroller receives the rotated message.
iOS Development-uitabbarcontroller Detailed