事实上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. Beads

    Beads 题目描述 Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串),每块有k(k>0)个珠子,如果这条珠子的长度不 ...

  2. HTTP协议详解之消息报头

    原文地址:http://www.cnblogs.com/devinzhang/archive/2012/02/06/2340186.html HTTP消息由客户端到服务器的请求和服务器到客户端的响应组 ...

  3. Use ASP.NET and DotNetZip to Create and Extract ZIP Files

    原文发布时间为:2011-02-16 -- 来源于本人的百度文章 [由搬家工具导入] Published: 11 Feb 2011By: Scott MitchellDownload Sample C ...

  4. Spy++使用方法

    原文转自 http://jingyan.baidu.com/article/3a2f7c2e76584a26aed61174.html 1.Spy++ 是Visual Studio 自带的工具(菜单& ...

  5. C#执行CMD命令并接收返回结果的实现方法

    using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using ...

  6. MPchartAndroid-柱状图

    mChart = (LineChart) findViewById(R.id.chart1); mChart.setDescription("");    //设置图表描述信息 m ...

  7. hdu 4990(数学,等比数列求和)

    Reading comprehension Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. 【原创】Javascript-显示系统时间

    /*JS-显示系统时间*/ function showLocale(objD) { var str, colorhead, colorfoot; var yy = objD.getYear(); if ...

  9. ZSTU 4248 KI的目标(dfs)

    KI的目标 Time Limit: 2 Sec  Memory Limit: 128 MB                                                        ...

  10. 平衡树之非旋Treap

    平衡树(二叉树) 线段树不支持插入or删除一个数于是平衡树产生了 常见平衡树:treap(比sbt慢,好写吧),SBT(快,比较好写,有些功能不支持),splay(特别慢,复杂度当做根号n来用,功能强 ...