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;