关于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 ...
随机推荐
- 移动端页面a input去除点击效果及pc端切换
1 手机端页面a button input去除点击效果以及闪屏问题 添加: a, button, input { -webkit-tap-highlight-color: rgba(255, 0, 0 ...
- octave学习
前置安装 octave introduction 杂 clear; close all; clc刷新清空octave 如果写程序后缀名.m help commandname帮助 ;用法同c++ %注释 ...
- 【BZOJ4542】大数(莫队)
题意:给定一个N位的由[0..9]组成的数字串和质数P,有M次不强制在线的询问,每次询问区间[l,r]中模P意义下为0的子串个数 N,M<=2e5,P<=1e10 思路:一次A,本来还以为 ...
- Ubuntu FireFox的“后退”按钮与Backspace键
我们都知道,大部分的网页浏览器和窗口管理器的“后退”按钮是和Backspace键关联的,这样会极大的方便并加快我们浏览时的翻页速度(我一直是左手 放在键盘上按快捷键,右手鼠标的姿势找文件和看网页的,省 ...
- Java反射获取类对象的三种方式
package demo01; /* * 获取一个类的class文件对象的三种方式 * 1.对象获取 * 2.类名获取 * 3.Class类的静态方法获取 */ public class Reflec ...
- Android中节操播放器JieCaoVideoPlayer使用
效果 使用 即便是自定义UI,或者对Library有过修改,也是这五步骤来使用播放器. 1.添加类库 compile 'cn.jzvd:jiaozivideoplayer:6.0.0' 2.添加布局 ...
- 怎样在action中获得值栈ValueStack中的值
1,实现RequestAware接口 //模拟对象 User model=new User(); user.setName=“lisi”;2,ValueStack value=(Value ...
- Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】
B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- httperf+autobench测试web应用
测试性能相关的概念理解 httperf使用 主页: http://www.hpl.hp.com/research/linux/httperf/ 下载: http://httperf.googleco ...
- 改变Ubuntu控制台字体大小(转)
输入 sudo dpkg-reconfigure console-setup 选择一个适合的字体和字号即可. 参考: http://www.codeweblog.com/%E6%94%B9%E5%8F ...