事实上iOS Tabbar的可定制性很高,我们没有必要反复造轮子,以下是笔者收集的一些tabbar的经常使用设置。希望对大家有所帮助。

设置tabbar选中颜色

iOS7设置例如以下:

[self.tabBarController.tabBarsetSelectedImageTintColor:[UIColor greenColor]];

ios8中例如以下设置:

self.tabBar.tintColor=[UIColor greenColor];

消除tabbar边框

在appdelegate的程序启动处:

[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];

[[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];

设置tabbar item原始图标与原始选中图标。而不是系统自己主动填充的颜色

    // 拿到 TabBar 在拿到想应的item
UITabBar *tabBar = _tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
// 对item设置对应地图片
item0.selectedImage = [[UIImage imageNamed:@"recognize-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
item0.image = [[UIImage imageNamed:@"recognize"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item1.selectedImage = [[UIImage imageNamed:@"life-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
item1.image = [[UIImage imageNamed:@"life"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item2.selectedImage = [[UIImage imageNamed:@"edit-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
item2.image = [[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item3.selectedImage = [[UIImage imageNamed:@"setting-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
item3.image = [[UIImage imageNamed:@"setting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

设置tabbar背景图片

    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 49)];
backView.backgroundColor = [UIColor redColor];
[self.tabBar insertSubview:backView atIndex:0];
self.tabBar.opaque = YES;

设置tabbar item选中时的背景图片

1、5.0以上版本号

     

self.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"system_tabbar_item_selected.png"];

2、5.0下面版本号

     首先实现例如以下方法:

- (void)setNoHighlistTabBar:(UITabBarController *)tabBarController
{
NSArray * tabBarSubviews = [tabBarController.tabBar subviews]; int index4SelView; if(tabBarController.selectedIndex+1 > 4)
{//selected the last tab.
index4SelView = [tabBarSubviews count]-1;
}
else if([tabBarController.viewControllers count] > 5)
{//have "more" tab. and havn't selected the last tab:"more" tab. index4SelView = [tabBarSubviews count] - 5 + tabBarController.selectedIndex;
}
else
{//have no "more" tab. index4SelView = [tabBarSubviews count] -
[tabBarController.viewControllers count] + tabBarController.selectedIndex;
}
if([tabBarSubviews count] < index4SelView+1)
{
assert(false);
return;
}
UIView * selView = [tabBarSubviews objectAtIndex:index4SelView]; NSArray * selViewSubviews = [selView subviews]; for(UIView * v in selViewSubviews)
{
if(v && [NSStringFromClass([v class]) isEqualToString:@"UITabBarSelectionIndicatorView"]) {//the v is the highlight view.
[self.selectedItemBgImageView removeFromSuperview];
[selView insertSubview:self.selectedItemBgImageView belowSubview:v]; [v removeFromSuperview]; break; }
}
}

改方法的实质就是循环tabBar的subViews, 找到tabBar中的这个view, 是一个UITabBarSelectionIndicatorView的view,然后把它替换成你自己创建的UIImageView, 上例中的self.selectedItemBgImageView.

  然后须要把UITabBarController的delegate设为self, 在tabBarController:didSelectViewController的代理方法中运行上面的方法:[self setNoHighlistTabBar:self];

 还有setSelectIndex:方法中也要运行[self setNoHighlistTabBar:self];

关于iOS Tabbar的一些设置的更多相关文章

  1. iOS 国际化多语言设置 xcode7

    iOS 国际化多语言设置 方式一: 1. 在storyboard中创建好UI,然后在 project 里面  Localizables 栏目里面,添加你需要的语言:默认是Englist; 比如这里我添 ...

  2. ios 屏幕方向的设置

    ref: http://www.cnblogs.com/niit-soft-518/p/5611298.html 实际的项目需求.root是TabBarController,里面有4个navigati ...

  3. iOS 10 之后权限设置

    iOS 10 之后权限设置 麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风? 相机权限: Privacy - Camera U ...

  4. ios系统中各种设置项的url链接

    ios系统中各种设置项的url链接 在代码中调用如下代码:NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];[[UIApplic ...

  5. ios下元素溢出设置 overflow:auto; 不能滑动解决办法

    ios下元素溢出设置 overflow:auto; 不能滑动解决办法: overflow:auto; overflow-y:scroll; -webkit-overflow-scrolling:tou ...

  6. iOS tabbar 图片,最佳大小方式

    iOS tabbar 图片,最佳大小方式 文档大小 30 *30 retaina 60 *60 最佳大小 48 *32 参考:http://stackoverflow.com/questions/15 ...

  7. iOS 控制器title和tabbar的title设置问题

    iOS 设置tabbarItem的title的是通过 controller.tabBarItem.title = @"标题" iOS 设置导航栏控制器title通过 contoll ...

  8. iOS tabbar 属性

    1.设置tabbar背景颜色 NSArray *controllers = [NSArray arrayWithObjects:nav_main,nav_channle,nav_me, nil]; _ ...

  9. UITabBarController 、TabBar背景颜色设置,UITabBarItem的文字样式(颜色和大小)UITabBarItem的位置调整

    改变UITabBarController的颜色 UIView*mView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,48)];//这是部分tabb ...

随机推荐

  1. Python 错误类型及解决方法

    SyntaxError: invalid syntax          表示“语法错误:不正确的语法” 检查代码的缩进,代码格式是否正确,Python的缩进一般为四个空格,tab键尽量不要用. In ...

  2. C++ 静态成员的类内初始化

    一般来说,关于C++类静态成员的初始化,并不会让人感到难以理解,但是提到C++ 静态成员的"类内初始化"那就容易迷糊了. 我们来看如下代码: //example.h #includ ...

  3. Python之数据结构:列表

    列表:处理一组有序项目的数据结构 一.基本操作 1.列表运算符 list1=[2,3,4,5,6,7,8] print len(list1) print [1,2]+[3,4] print ['Hi' ...

  4. js 一/二维数组排序

    JavaScript中数组排序方法 用到的最多的当然是封装好的sort()方法了 一:sort()方法怎么使用? sort方法并不像我们想的那么容易使用,不是单纯的arr.sort()就行了,需要我们 ...

  5. Windows + Eclipse 构建mahout运行环境

    mahout的完整运行还是需要hadoop的支持的,不过很多算法只需要能把hadoop的jar包加入到classpath之中就能正常运行. 比如我们在使用LogisticModelParameters ...

  6. 从数据库的表导出到Excel表格中【让客户端下载的Excel】

    原文发布时间为:2008-10-11 -- 来源于本人的百度文章 [由搬家工具导入] 这个例子是从gridview中导出到Excel,可以举一反三,可以直接从数据库中取值放在DataSet中,然后再从 ...

  7. [LeetCode] Search Insert Position 二分搜索

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  8. request库

    0x00  环境简介和安装 我这里使用的是python2.7版本,直接使用pycharm2018这款IDE. 首先在pycharm中配置一下virtualenv环境,virtualenv是一个创建独立 ...

  9. delphi 窗体透明详解TransparentColorValue,窗体透明控件不透明

    关于窗体透明的做法 来自:http://blog.csdn.net/shuaihj/article/details/8610343 关于窗体透明的做法 1.在Delphi中,设置窗体的AlphaBle ...

  10. 记录: 一次解决整型溢出攻击(使用scala,隐式转换)

    最近项目遇到一次整型溢出攻击 有一个功能,玩家购买num个物品. 每个物品花费14货币. 客户端限制玩家只能购买 1-9999个该物品. 但是某玩家通过技术手段,获得了客户端的运行权限. 于是发送协议 ...