UITabBarController 、TabBar背景颜色设置,UITabBarItem的文字样式(颜色和大小)UITabBarItem的位置调整
改变UITabBarController的颜色
UIView*mView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,48)];//这是部分tabbar的颜色
[mView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"ydy1.jpg"]]];
[self.tabBar insertSubview:mView atIndex:1];
mView.alpha=0.8;
效果如图:

设置tabBar的背景色
第一种方式:
[[UITabBar appearance] setBackgroundColor:[UIColor redColor]];//测试时不起作用
[[UITabBar appearance] setBarTintColor:[UIColor redColor]];//这样写才能达到效果。
如果想要得到想要的颜色需要再另外添加一句:
[UITabBar appearance].translucent = NO;// 这句表示取消tabBar的透明效果。
第二种方式:在tabBar上添加一个有颜色的View
UIView *view= [[UIView alloc]init];
view.backgroundColor=[UIColor redColor];
view.frame=self.tabBar.bounds;
[[UITabBar appearance] insertSubview:view atIndex:0];
第三种方式:使用背景图片:
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabBarBackgroundImage"]];
[UITabBar appearance].translucent = NO;
UITabBarItem的文字样式(颜色和大小)
#define WYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
// 第一种写法
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = WYColor(123, 123, 123);
textAttrs[NSFontAttributeName]=[UIFont fontWithName:@"Helvetica" size:12.0f];
NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
selectTextAttrs[NSForegroundColorAttributeName] = WYColor(50, 156, 245);
selectTextAttrs[NSFontAttributeName]=[UIFont fontWithName:@"Helvetica" size:18.0f];
[[UITabBarItem appearance] setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
// 第二种写法
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:19.0f],NSFontAttributeName,nil] forState:UIControlStateSelected];
注意:1、设置字体的时候要选择支持中文的字体,不然的话修改字号是无效的,比如字体设置成“ProximaNova-Semibold”。这种字体本身只支持英语,不支持中文,所以使用该字体并不能调整字体大小。
2、如果文字太大的话,会和图片靠的很近,这个时候我们可以让UI设计师给我们切图的时候多留一点边白就可以解决。
UITabBarItem的选中和非选中图片
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
nav.tabBarItem.image =[[UIImage imageNamed:@"unselect"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav.tabBarItem.selectedImage =[[UIImage imageNamed:@"select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav.tabBarItem.title = @"yoowei";
[self addChildViewController:nav];
调整各个ITEM的位置
//未选中的图片(上面的数组没有列出)
UIImage *unselectedImage = [UIImage imageNamed:nor_images[i]];
unselectedImage = [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//选中的图片
UIImage *selectedImage = [UIImage imageNamed:select_images[i]];
selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:arrayName[i] image:unselectedImage selectedImage:selectedImage];
//设置背景图片的内凹变化,正值向内缩小,负值向外延伸
UIEdgeInsets insets;
insets.left = -5;
insets.right = -5;
tabBarItem.imageInsets = insets;
//设置item.title位置偏移
UIOffset offset;
offset.horizontal = 30;
offset.vertical = -10;
[tabBarItem setTitlePositionAdjustment:offset];
效果如下:(虽然很难看,但是效果达到了)。

UITabBarController 、TabBar背景颜色设置,UITabBarItem的文字样式(颜色和大小)UITabBarItem的位置调整的更多相关文章
- iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色
btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...
- 设置UIButton的文字显示位置、字体的大小、字体的颜色
btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...
- android textview改变部分文字的颜色和string.xml中文字的替换(转)
转 :http://blog.csdn.net/ljz2009y/article/details/23878669 一:TextView组件改变部分文字的颜色: TextView textView ...
- MAC 终端颜色设置
在bash中,可以通过更改PS1环境变量的值来设置提示行.通常的提示符颜色单调,用户可以通过在PS1中添加颜色代码序列来设置提示符中不同信息以不同颜色显示. 添加颜色相当容易:第一步是设计不带颜色的提 ...
- css单位分析、颜色设置与调色板
CSS单位分析 px:单位代表像素,1px代表一个像素点. %:设置子元素为父容器的占比. em:代表该元素中一个字体所占字符,常用在文字首行缩进.其具有继承性. rem:始终代表html中的字符所在 ...
- iOS开发UITableViewCell的选中时的颜色设置(转)
iOS开发UITableViewCell的选中时的颜色设置 1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyle ...
- 梦想CAD控件COM接口文字样式
增加文字样式 用户可以增加文字样式到数据库,并设置其字体等属性,具体实现c#代码如下: private void CreateText() { MxDrawApplication app = new ...
- 梦想CAD控件网页版文字样式
增加文字样式 用户可以增加文字样式到数据库,并设置其字体等属性,具体实现js代码如下: function CreateText(){ //返回控件的数据库对象 var database =mxOcx. ...
- [BS-03] 统一设置UITabBarController管理的所有VC的tabBarItem图标文字的颜色大小等属性
1. 统一设置UITabBarController管理的所有VC的tabBarItem图标文字的颜色大小等属性 . 统一设置UITabBarController管理的所有VC的tabBarItem图标 ...
随机推荐
- iOS 10 的坑:新机首次安装 app,请求网络权限“是否允许使用数据”(转)
症状 iOS 10 之后,陆陆续续地有用户联系我们,说新机第一次安装.第一次启动的时候,app 首屏一片空白,完全没数据.kill 掉重新打开就好了. 一开始以为是用户网络情况不好,但随着越来越多的用 ...
- [已解决]从微软合作伙伴资源和MSDN下载系统和软件Microsoft download Manager无效
有个itellyou,更新了所有MSDN的软件包.如果自己有微软的注册账户,还是从微软官网下载比较好.而且对自己账户里的系统和itellyou里的做了对比.发现SHA1码不相同,估计官方分配的序列号也 ...
- JustWeTools - 自定义控件集
JustWeTools - Some useful tools 项目地址 JustWe 现在有哪些模块? View自定义控件 PaintView画图工具(包含重构压感新版) CodeView代码编辑 ...
- [excel玩转表格教程][1G][AVI]
[excel玩转表格教程][1G][AVI] 下载地址 :http://www.fu83.cn/thread-222-1-1.html
- 第1章 重构,第一个案例(2):分解并重组statement函数
2. 分解并重组statement (1)提炼switch语句到独立函数(amountFor)和注意事项. ①先找出函数内的局部变量和参数:each和thisAmount,前者在switch语句内未被 ...
- android第一行代码-6.自定义控件的实现
0.假设一个应用中标题栏控件都是共用的,如果每个activity都需要设置button,绑定方法,那代码就会很臃肿.那我们可以自定义控件,然后继承这个控件就行了. 自定义控件为TitleLayout, ...
- HDU 3032 Nim or not Nim (sg函数)
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...
- protobuf简介
#1,简介 把某种数据结构的信息,以某种格式保存起来: 主要用于数据存储,传输协议格式. #2,优点 性能好 反观XML的缺点:解析的开销惊人,不适用于事件性能敏感的场合:为了有较好的可读性,引入一些 ...
- 基于SoCkit的opencl实验1-基础例程
基于SoCkit的opencl实验1-基础例程 准备软硬件 Arrow SoCkit Board 4GB or larger microSD Card Quartus II v14.1 SoCEDS ...
- 关于dll
今日看到一个不带dllmain的dll,忽然觉得有点奇怪,然后查了一下,原来dll还可以不需要dllmain,甚至可以自己定义入口 先mark以下的资料,有空再总结一下...同时dll劫持,有必要亲身 ...