网站地图    收藏   

主页 > 后端 > php资料库 >

IOS学习笔记UITabBarController_自学php网

来源:自学PHP网    时间:2014-12-04 22:12 作者: 阅读:

[导读] 实现一个简单的UITabBar: AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Over...

实现一个简单的UITabBar:

AppDelegate.m

- (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 = @"王振";
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

<

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.title = @"首页";
self.tabBarItem.badgeValue = @"New";

}
return self;
}

-(void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
view.backgroundColor = [UIColor whiteColor];
self.view = view;

}

技巧:
给Iphone图标添加数字提示:self.tabBarItem.badgeValue = 8;
 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论