设置uitabbar的效果

http://www.cocoachina.com/bbs/simple/?t124524.html


下面的代码,对iOS (5.0 and later)有效。
// 设置TabBar的外貌
- (void)setTabBarAppearance
{
    UITabBar *tabBar = self.tabBarController.tabBar;
    
    // tabBar的整个背景条
    tabBar.backgroundImage = [UIImage imageNamed:@"底部bar"];
    // tabBar的单个tab的选择指示
    tabBar.selectionIndicatorImage = [UIImage imageNamed:@"底部bar_选中"];
    
    //
    // tabBar“选择”和“未选择”时的图片,带透明通道
    //
    UIImage *selectedImage0 = [UIImage imageNamed:@"1_on"];
    UIImage *unselectedImage0 = [UIImage imageNamed:@"1_nm"];
    
    UIImage *selectedImage1 = [UIImage imageNamed:@"2_on"];
    UIImage *unselectedImage1 = [UIImage imageNamed:@"2_nm"];
    
    UIImage *selectedImage2 = [UIImage imageNamed:@"3_on"];
    UIImage *unselectedImage2 = [UIImage imageNamed:@"3_nm"];
    
    UIImage *selectedImage3 = [UIImage imageNamed:@"4_on"];
    UIImage *unselectedImage3 = [UIImage imageNamed:@"4_nm"];
    
    UIImage *selectedImage4 = [UIImage imageNamed:@"5_on"];
    UIImage *unselectedImage4 = [UIImage imageNamed:@"5_nm"];
    
    NSArray *selectedImageArray = [NSArray arrayWithObjects:
                                   selectedImage0,
                                   selectedImage1,
                                   selectedImage2,
                                   selectedImage3,
                                   selectedImage4,
                                   nil];
    
    NSArray *unselectedImageArray = [NSArray arrayWithObjects:
                                     unselectedImage0,
                                     unselectedImage1,
                                     unselectedImage2,
                                     unselectedImage3,
                                     unselectedImage4,
                                     nil];
    
    int count = [tabBar.items count];
    for (int i=0; i<count; ++i)
    {
        UITabBarItem *item = [tabBar.items objectAtIndex:i];
        
        [item setFinishedSelectedImage:[selectedImageArray objectAtIndex:i] withFinishedUnselectedImage:[unselectedImageArray objectAtIndex:i]];
        
        // 选中时的字体属性
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIColor whiteColor], UITextAttributeTextColor,
                                      [UIFont systemFontOfSize:12.0], UITextAttributeFont,
                                      nil] forState:UIControlStateSelected];
        
        // 未选中时的字体属性
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIColor colorWithRed:0x3c/255.0 green:0x80/255.0 blue:0x1a/255.0 alpha:1.0], UITextAttributeTextColor,
                                      [UIFont systemFontOfSize:12.0], UITextAttributeFont,
                                      nil] forState:UIControlStateNormal];
    }
}

上一篇:ios合并模拟器和真机静态库


下一篇:部署Csico三层交换机专家级访问控制列表的配置案例实战