关于iOS Tabbar的一些设置
事实上iOS 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的一些设置的更多相关文章
- iOS 国际化多语言设置 xcode7
iOS 国际化多语言设置 方式一: 1. 在storyboard中创建好UI,然后在 project 里面 Localizables 栏目里面,添加你需要的语言:默认是Englist; 比如这里我添 ...
- ios 屏幕方向的设置
ref: http://www.cnblogs.com/niit-soft-518/p/5611298.html 实际的项目需求.root是TabBarController,里面有4个navigati ...
- iOS 10 之后权限设置
iOS 10 之后权限设置 麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风? 相机权限: Privacy - Camera U ...
- ios系统中各种设置项的url链接
ios系统中各种设置项的url链接 在代码中调用如下代码:NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];[[UIApplic ...
- ios下元素溢出设置 overflow:auto; 不能滑动解决办法
ios下元素溢出设置 overflow:auto; 不能滑动解决办法: overflow:auto; overflow-y:scroll; -webkit-overflow-scrolling:tou ...
- iOS tabbar 图片,最佳大小方式
iOS tabbar 图片,最佳大小方式 文档大小 30 *30 retaina 60 *60 最佳大小 48 *32 参考:http://stackoverflow.com/questions/15 ...
- iOS 控制器title和tabbar的title设置问题
iOS 设置tabbarItem的title的是通过 controller.tabBarItem.title = @"标题" iOS 设置导航栏控制器title通过 contoll ...
- iOS tabbar 属性
1.设置tabbar背景颜色 NSArray *controllers = [NSArray arrayWithObjects:nav_main,nav_channle,nav_me, nil]; _ ...
- UITabBarController 、TabBar背景颜色设置,UITabBarItem的文字样式(颜色和大小)UITabBarItem的位置调整
改变UITabBarController的颜色 UIView*mView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,48)];//这是部分tabb ...
随机推荐
- git本地仓库关联远程仓库
1. git init 2. git add . 3. git commit -am "###" -------以上3步只是本地提交 4.git remote add o ...
- Codeforces Round #323 (Div. 2) A 水
A. Asphalting Roads time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Hyperledger Fabric 环境配置
简单说一下 Hyperledger Fabric的配置 1.第一步,安装curl brew install curl 注:没有brew的自行百度(mac) 2. 安装Docker 下载并安装Docke ...
- pat 甲级 1066. Root of AVL Tree (25)
1066. Root of AVL Tree (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue An A ...
- [Oracle] Lock&Latch梳理
Oracle lock&latch 1. 概述 4种锁机制 lock latch pin mutex 保证资源在并发访问和修改时不被破坏 锁类型 行为 持有时间 级别 保护类型 lock 队列 ...
- python c++ Visual Studio相关 Unable to find vcvarsall.bat问题
使用Cython编译包的时候报错: Unable to find vcvarsall.bat 说明:https://jingyan.baidu.com/article/adc815138162e8f7 ...
- hdu 3579(中国剩余定理+考虑0)
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- LeetCode OJ--Linked List Cycle **
https://oj.leetcode.com/problems/linked-list-cycle/ 判断一个链表是否为循环链表(这个链表可能是 1 2 3 4 然后4指向2) 巧妙的方法:设置两个 ...
- Codeforces 761D Dasha and Very Difficult Problem(贪心)
题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...
- Oracle并发控制、事务管理学习笔记
(a)基本概念 锁的2种最基本.最简单的类型:排他锁(eXclusive lock,即X锁).共享锁(Share lock,即S锁). 不同级别的锁定协议及其作用: 申请的锁 及其作用 锁定协议 修改 ...