Examples of uitabbarcontroller used in IOS development _ios

Source: Internet
Author: User

First, let's take a look at its view level diagram:

Copy Code code as follows:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
Override point for customization after application launch.
Self.window.backgroundColor = [Uicolor Whitecolor];

#pragma mark-Set Tabbaritem
#pragma Mark's first view Viewcontroller

Hmt_aviewcontroller * Tabbarviewa = [[Hmt_aviewcontroller alloc] init];
Set a view----the label bar title text (refer to micro-letters or QQ experience)
TabBarViewA.tabBarItem.title = @ "micro-letter";
Set a view----the tab bar picture (because you do not have a picture, here casually set a name)
TabBarViewA.tabBarItem.image = [UIImage imagenamed:@ "1.png"];
Set a view----the tab bar information hint (live: Badgevalue is nsstring type below set 3, just like QQ message has 3 not accepted, give a person a reminder)
TabBarViewA.tabBarItem.badgeValue = @ "3";
IOS7 Discard the----tab bar when selected to display a picture, when not selected to display another picture
[Tabbarviewa.tabbaritem SetFinishedSelectedImage:actionMenu.selectedIcon Withfinishedunselectedimage: Actionmenu.icon];
iOS7 method (own no picture, so the picture inside the code is a random name, no practical significance)
TabBarViewA.tabBarItem.selectedImage = Actionmenu.selectedicon;

#pragma Mark's second view Viewcontroller
Second View Viewcontroller
Hmt_bviewcontroller * TABBARVIEWB = [[Hmt_bviewcontroller alloc] init];
Set----tab bar in B view
Set with the system-supplied identification (which can be counted equivalent to icons and text) (parameter: Uitabbarsystemitem is an enumerated value, what form would you like to find in the API provided by the system)
Tabbarviewb.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemsearch tag:1];
Set the----tab bar information in B view tips
TabBarViewB.tabBarItem.badgeValue = @ "Go";

#pragma mark Third View Viewcontroller
Hmt_cviewcontroller * TABBARVIEWC = [[Hmt_cviewcontroller alloc] init];
Tabbarviewc.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemdownloads tag:2];
Set the----tab bar information in B view tips
TabBarViewC.tabBarItem.badgeValue = @ "new";

#pragma mark Fourth View Viewcontroller
Hmt_dviewcontroller * tabbarviewd = [[Hmt_dviewcontroller alloc] init];
Tabbarviewd.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemfavorites Tag:3];
Set the----tab bar information in B view tips
TabBarViewD.tabBarItem.badgeValue = @ "99";

#pragma mark Fifth View Viewcontroller
Hmt_eviewcontroller * Tabbarviewe = [[Hmt_eviewcontroller alloc] init];
Tabbarviewe.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemhistory tag:4];
Set the----tab bar information in B view tips
TabBarViewE.tabBarItem.badgeValue = @ "Sky";

#pragma mark Sixth view Viewcontroller (the maximum number of views that the system defaults to display is 5)
* * If your viewcontrollers attribute adds more than five items, the tab bar controller will automatically insert a special view controller.
Called more view controller, the controller will be responsible for managing more than the items, this more view controller provides a custom interface,
Use table to render superfluous view controller, and the number of view controller is unrestricted.
Hmt_fviewcontroller * TABBARVIEWF = [[Hmt_fviewcontroller alloc] init];
Tabbarviewf.tabbaritem = [[Uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemcontacts Tag:5];
Set----tab bar information in F View tips
TabBarViewF.tabBarItem.badgeValue = @ "AG";



#pragma mark-Set Tabbarcontroller

Create Tabbarcontroller
Uitabbarcontroller * Tabbarcontroller = [[Uitabbarcontroller alloc]init];
Tabbarcontroller default is at the bottom, if you want to adjust the position, you can do the following 2 operations (44 is the iphone Tabbarcontroller and Uinavigationcontroller standard height)
CGRect frame = CGRectMake (0, 20, 320, 44);
TabBarController.tabBar.frame = frame;
Each tab must have a content View controller------->viewcontrollers attribute that is used to deposit an application Tabbarcontroller how many interface switches
Tabbarcontroller.viewcontrollers = [Nsarray arraywithobjects:tabbarviewa,tabbarviewb,tabbarviewc,tabbarviewd, TABBARVIEWE,TABBARVIEWF, nil Nil];
Set coloring
TabBarController.tabBar.tintColor = [Uicolor Greencolor];
When setting the selected picture
TabBarController.tabBar.selectedImageTintColor = [Uicolor Browncolor];
Set a background picture (no pictures of yourself, no settings)
TabBarController.tabBar.backgroundImage = [UIImage imagenamed:@ "];
Set the default Viewcontroller view when the program starts (set to 3, a total of 5 viewcontroller, the view displayed when you come in is the 4th-tabbarviewd, subscript starting from 0)
Tabbarcontroller.selectedindex = 3;


Self.window.rootViewController = Tabbarcontroller;

[Self.window makekeyandvisible];
return YES;
}

The final effect of the following figure:

Uitabbarcontroller Proxy method and modal display
First to implement the Protocol <UITabBarControllerDelegate>

Copy Code code as follows:
Set up agents
Tabbarcontroller.delegate =self;
Uinavigationcontroller *nav = Tabbarcontroller.morenavigationcontroller;
[Nav Setnavigationbarhidden:yes Animated:yes];

Control which Viewcontroller tabs can be clicked
-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontrollershouldselectviewcontroller: (UIViewController *) viewcontroller{
Representative Hmt_cviewcontroller This view cannot be displayed and cannot be clicked to the tab bar represented by it
if ([Viewcontrolleriskindofclass:[hmt_cviewcontrollerclass]]) {
Returnno;
}
Returnyes;
}

Check which tab bar, a monitoring function.
-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontrollerdidselectviewcontroller: (Uiviewcontroller *) viewcontroller{

}

More view controller will begin editing
-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontrollerwillbegincustomizingviewcontrollers: (NSArray *) viewcontrollers{

}
More view controller will end edit
-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontrollerwillendcustomizingviewcontrollers: (NSArray *) Viewcontrollers changed: (BOOL) changed{

}
More View controller Edit
-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontrollerdidendcustomizingviewcontrollers: (NSArray *) Viewcontrollers changed: (BOOL) changed{

}

#import "Hmt-aviewcontroller.h"
#import "HMTModalShowViewController.h"

@interfaceHMT_AViewController ()
@end

@implementation Hmt_aviewcontroller

-(void) viewdidload
{
[Superviewdidload];
Self.view.backgroundColor = [Uicolorredcolor];

Create a button
UIButton * button = [UIButton buttonwithtype:uibuttontypedetaildisclosure];
Button.frame =cgrectmake (100,100,100, 100);
[Button addtarget:self action: @selector (Modalshow) forcontrolevents:uicontroleventtouchupinside];
[Self.view Addsubview:button];
Do no additional setup after loading the view.
}

-(void) modalshow{

Hmtmodalshowviewcontroller * MODALSHOWVC = [[Hmtmodalshowviewcontroller alloc]init];

Visual effects of modal view controllers when they appear
Modalshowvc.modaltransitionstyle =uimodaltransitionstylecrossdissolve;
/*
uimodaltransitionstylecoververtical = 0,//default, from bottom up
Uimodaltransitionstylefliphorizontal,//Horizontal rotation effect
Uimodaltransitionstylecrossdissolve,//gradient effect
Uimodaltransitionstylepartialcurl,//page Flip effect
*/
Mode view controller rendering, default Full-screen
Modalshowvc.modalpresentationstyle =uimodalpresentationfullscreen;
/*
Uimodalpresentationfullscreen = 0,
Uimodalpresentationpagesheet,
Uimodalpresentationformsheet,
Uimodalpresentationcurrentcontext,
Uimodalpresentationcustom,
Uimodalpresentationnone =-1,
*/

Uinavigationcontroller * MODALSHOWNC = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:MODALSHOWVC];

Launch modal View Controller
[Self PRESENTVIEWCONTROLLER:MODALSHOWNC animated:yes completion:^{
NSLog (@ "Hello World");
}];
}


#import "HMTModalShowViewController.h"

@interfaceHMTModalShowViewController ()

@end

@implementation Hmtmodalshowviewcontroller

-(void) viewdidload
{
[Superviewdidload];
Do no additional setup after loading the view.

Self.view.backgroundColor = [Uicolor Yellowcolor];

Using Uinavigationcontroller to implement exit controller
Uibarbuttonitem * Barbutton = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target: Self action: @selector (Modaldismiss)];

Self.navigationItem.leftBarButtonItem = Barbutton;
Self.navigationItem.title =@ "Humingtao";

Create a button to implement the exit controller
/* UIButton * button = [UIButton buttonwithtype:uibuttontypedetaildisclosure];
Button.frame = CGRectMake (100, 100, 100, 100);
[Button addtarget:self action: @selector (Modaldismiss) forcontrolevents:uicontroleventtouchupinside];

[Self.view addsubview:button];*/

}

-(void) modaldismiss{
Exit modal View Controller
[Self Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Exit Goodbye");
}];
}
@end


Related Article

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.