设置uitabbar的效果

简介: http://www.cocoachina.com/bbs/simple/?t124524.html 下面的代码,对iOS (5.0 and later)有效。

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];
    }
}

目录
相关文章
|
Swift iOS开发 Perl
如何解决Swift混编的module编译错误
前言很多iOS工程都是基于Object-C开发,再逐步向Swift演进,演进过程中不可避免要进行Swift混编。Swift模块需要支持LLVM Module规范,混编工程会遇到各种Module编译错误。这对于不熟悉的同学来说简直是灾难,严重影响开发效率。本文会介绍常见的Module编译错误,希望对大家有所帮助。常见错误1:Could not build module xxx当一个OC模块引用了Sw
7735 1
如何解决Swift混编的module编译错误
|
Web App开发 iOS开发
Mac Safari 配置 IE 代理 (支持 IE 调试)
Mac Safari 配置 IE 代理 (支持 IE 调试)
1543 0
|
监控 开发者 iOS开发
iOS第三方网络诊断库——LDNetDiagnoService
iOS第三方网络诊断库——LDNetDiagnoService
770 0
|
3天前
|
搜索推荐 编译器 Linux
一个可用于企业开发及通用跨平台的Makefile文件
一款适用于企业级开发的通用跨平台Makefile,支持C/C++混合编译、多目标输出(可执行文件、静态/动态库)、Release/Debug版本管理。配置简洁,仅需修改带`MF_CONFIGURE_`前缀的变量,支持脚本化配置与子Makefile管理,具备完善日志、错误提示和跨平台兼容性,附详细文档与示例,便于学习与集成。
271 116
|
18天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
12天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
663 219