您的位置:首页 > 产品设计 > UI/UE

UI UITabBarController

2015-04-28 19:34 260 查看
<span style="font-size:18px;">AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

UITabBarController *tabVC=[[UITabBarController alloc]init];
//凡是实现UIAppearance协议的类,都可以实现类似一键换肤的功能。设置所有导航条的颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];

//首页
HomeViewController *homeVC=[[HomeViewController alloc]init];
UINavigationController *homeNC=[[UINavigationController alloc]initWithRootViewController:homeVC];
//搜索
SearchViewController *searchVC=[[SearchViewController alloc]init];
UINavigationController *searchNC=[[UINavigationController alloc]initWithRootViewController:searchVC];
//收藏
FavorViewController *favorVC=[[FavorViewController alloc]init];
UINavigationController *favorNC=[[UINavigationController alloc]initWithRootViewController:favorVC];

FourViewController *fourVC=[[FourViewController alloc]init];
UINavigationController *fourNC=[[UINavigationController alloc]initWithRootViewController:fourVC];

FiveViewController *fiveVC=[[FiveViewController alloc]init];
UINavigationController *fiveNC=[[UINavigationController alloc]initWithRootViewController:fiveVC];

SixViewController *sixVC=[[SixViewController alloc]init];
UINavigationController *sixNC=[[UINavigationController alloc]initWithRootViewController:sixVC];

//将试图装入tabVC
tabVC.viewControllers=@[homeNC,searchNC,favorNC,fourNC,fiveNC,sixNC];

//设置tabBar上字体的颜色
tabVC.tabBar.tintColor=[UIColor redColor];
//设置tabBar的颜色
tabVC.tabBar.barTintColor=[UIColor blueColor];

//设置背景图片
[tabVC.tabBar setBackgroundImage:[UIImage imageNamed:@"1.png"]];
//把边缘以外的内容
tabVC.tabBar.clipsToBounds=YES;

//选中某一个页面
tabVC.selectedIndex=1;
//设置代理
tabVC.delegate=self;

self.window.rootViewController=tabVC;
[tabVC release];
[homeVC release];
[homeNC release];
[searchVC release];
[searchNC release];
[favorVC release];
[favorNC release];
[fourVC release];
[fourNC release];
[fiveNC release];
[fiveVC release];
[sixNC release];
[sixVC release];

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"%d",tabBarController.selectedIndex);
}
</span>
<pre name="code" class="objc"><span style="font-size:18px;">HomeViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//设置navigationBar和tabBar上的title
//放在viewDidLoad方法中不点击是不加载是不会显示的,所以在初始化方法中写
self.title=@"首页";

UITabBarItem *item=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:100];
//设置badgeValue(右上角信息数)
item.badgeValue=@"1";
self.tabBarItem=item;
[item release];

//        //图片是镂空的
//        UIImage *img=[[UIImage imageNamed:@"2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//        UITabBarItem *item=[[UITabBarItem alloc]initWithTitle:@"首页" image:img tag:100];
//        self.tabBarItem=item;
//        [item release];

}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor yellowColor];

}
</span>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: