UITabBar分栏控制器

 /*  分栏控制器基础流程
     *  第一步:把需要展示的页面创建出来。
     *  第二步:如果需要,就把页面封装到导航里
     *  第三步:设置每个页面/导航对应的专用按钮(tabBar上的)
     *  第四步:把这些页面/导航放到数组里,并和tabBarController关联
     */

 1 /*******分栏控制器的专用按钮,是让每个页面单独设置的********/
 2     
 3     UITabBarItem *atbi = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0    ];
 4     //使用系统自带的风格创建分栏专用按钮
 5     anc.tabBarItem = atbi;
 6     [atbi release];
 7     
 8     UITabBarItem *btib = [[UITabBarItem alloc] initWithTitle:@"bb" image:[UIImage imageNamed:@"tab0_2"] tag:0];
 9     //使用标题和图片创建(标准大小是30*30(60*60))
10     bv.tabBarItem = btib;
11     [btib release];
12     
13     UITabBarItem *ctbi = [[UITabBarItem alloc] initWithTitle:@"ctbi" image:[UIImage imageNamed:@"tab1_1"] selectedImage:[UIImage imageNamed:@"tab1_2"]];
14     //使用标题和2张图片创建
15     cv.tabBarItem = ctbi;
16     [ctbi release];
17     
18     self.viewControllers = [NSArray arrayWithObjects:anc, bv, cv, dv, nil];
19     
20     [anc release];
21     [bv release];
22     [cv release];
23     [dv release];
24     
25     self.tabBar.tintColor = [UIColor greenColor];
26     //内容的渲染色
27     
28     self.tabBar.barTintColor = [UIColor blackColor];
29     //背景色
30     
31     self.tabBar.backgroundImage = [UIImage imageNamed:@"tabbg"];
32     //背景图片
33     
34     //设置anc的title上的文字字体和颜色
35     NSDictionary *titleDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, [UIColor redColor], NSForegroundColorAttributeName, nil];
36     
37     anc.navigationBar.titleTextAttributes = titleDic;
38     //设置导航条上title的文字属性(针对整个导航有效)
39     
40     [atbi setTitleTextAttributes:titleDic forState:UIControlStateNormal];
41     //设置tabBar上专用按钮的文字属性(一般不设颜色)

  dv.hidesBottomBarWhenPushed = YES;
    //当新页面被push的时候,自动隐藏底部tabBar,返回时也会自动出现

posted @ 2015-04-02 15:07  Angelone  阅读(289)  评论(0编辑  收藏  举报