iOS Learning notes Uitabbarcontroller Use Tutorial

Source: Internet
Author: User

To achieve a simple uitabbar:

Appdelegate.m

The code is as follows Copy Code

-(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];
[Self.window makekeyandvisible];



Uilabel *lab = [[Uilabel alloc]initwithframe:cgrectmake (320/2-140/2, 80, 140, 40)];
Lab.text = @ "rocker Wang";
Lab.textalignment = Uitextalignmentcenter;
Lab.backgroundcolor = [Uicolor Bluecolor];
[Self.window Addsubview:lab];

Your code
Uilabel *label = [[Uilabel alloc]initwithframe:cgrectmake (320/2-140/2,480/2-40/2, 140, 40)];
Label.text = @ "Hello World";
Label.backgroundcolor = [Uicolor Cyancolor];
Label.textalignment = Uitextalignmentcenter;
[Self.window Addsubview:label];

Homeviewcontroller *view1 = [[Homeviewcontroller alloc]init];
Uinavigationcontroller *v1 = [[Uinavigationcontroller alloc]initwithrootviewcontroller:view1];


Messageviewcontroller *view2 = [[Messageviewcontroller alloc]init];
Uinavigationcontroller *v2 = [[Uinavigationcontroller alloc]initwithrootviewcontroller:view2];

Searchviewcontroller *VIEW3 = [[Searchviewcontroller alloc]init];
Uinavigationcontroller *v3 = [[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:VIEW3];

Settingviewcontroller *view4 = [[Settingviewcontroller alloc]init];
Uinavigationcontroller *v4 = [[Uinavigationcontroller alloc]initwithrootviewcontroller:view4];


Nsarray *arr = @[view1,view2,view3,view4];

Nsarray *viewcontrollers = [Nsarray arraywithobjects:v1,v2,v3,v4, Nil];


Uitabbarcontroller *mainviewcontroller = [[Uitabbarcontroller alloc]init];
Mainviewcontroller.viewcontrollers = viewcontrollers;
[Mainviewcontroller Setviewcontrollers:mainviewcontroller];

[Mainviewcontroller release];
[UIApplication sharedapplication].applicationiconbadgenumber = 2;

[Self.window Setrootviewcontroller:mainviewcontroller];


return YES;
}

Homeviewcontroller.m

  code is as follows copy code
-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil
{
self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil];
if (self) {
Custom initialization
Self.title = @ "Home";
Self.tabBarItem.badgeValue = @ "New";

}
return self;
}

-(void) Loadview
{
UIView *view = [[UIView alloc] Initwithframe:[[uiscreen Mainscreen] applicationframe]];
View.backgroundcolor = [Uicolor Whitecolor];
Self.view = view;

}

Skills:
Add a digital hint to the iphone icon: Self.tabBarItem.badgeValue = 8;

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.