iOS 自定义各类bar的属性
在iOS应用开发中,经常需要为导航栏和标签栏设置相同的主题,一个一个去设置的话,就太麻烦了,可以通过对应用中所有的导航栏和标签栏同意设置背景、字体等属性。
如:创建一个继承自“UINavigationController”的公共父类,然后应用中所有的NavigationController都继承UINavigationController,通过在UINavigationController类中的类方法
initialize中对导航栏属性进行设置,就会对项目中所有的导航栏控制器起作用
示例代码如下:
+ (void)initialize
{ #warning 可以通过设置UITabBar主题的方式来修改UITabBar中按钮的颜色
UITabBar *tabBar = [UITabBar appearance];
NSMutableDictionary *tabAttrs = [NSMutableDictionary dictionary];
tabAttrs[UITextAttributeTextColor] = [UIColor orangeColor];
[tabBar setTintColor:[UIColor orangeColor]]; // 1 设置UINavigationBar
UINavigationBar *navBar = [UINavigationBar appearance]; //1.1 设置状态栏
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque; //1.2 设置背景图片
[navBar setBackgroundImage:[UIImage imageWithName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault]; //1.3.设置字体
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[UITextAttributeTextColor] = [UIColor blackColor];
attrs[UITextAttributeTextShadowOffset] = [NSValue valueWithCGSize:CGSizeMake(, )];
attrs[UITextAttributeFont] = [UIFont systemFontOfSize:]; [navBar setTitleTextAttributes:attrs]; //2 设置导航条按钮主题
UIBarButtonItem *barItem = [UIBarButtonItem appearance];
//2.1 设置背景图
[barItem setBackButtonBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackButtonBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[barItem setBackButtonBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
//2.2 设置字体属性
NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionary]; itemAttrs[UITextAttributeTextColor] = iOS7 ? [UIColor orangeColor] : [UIColor blackColor];
itemAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithCGSize:CGSizeMake(, )];
itemAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:];
[barItem setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
}
iOS 自定义各类bar的属性的更多相关文章
- iOS 自定义Tabbar实现push动画隐藏效果
http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...
- iOS开发UI篇—transframe属性(形变)
iOS开发UI篇—transframe属性(形变) 1. transform属性 在OC中,通过transform属性可以修改对象的平移.缩放比例和旋转角度 常用的创建transform结构体方法分两 ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- iOS开发UI篇—transframe属性(形变)
iOS开发UI篇—transframe属性(形变) 1. transform属性 在OC中,通过transform属性可以修改对象的平移.缩放比例和旋转角度 常用的创建transform结构体方法分两 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
- iOS自定义转场动画实战讲解
iOS自定义转场动画实战讲解 转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- 李洪强iOS开发Swift篇—09_属性
李洪强iOS开发Swift篇—09_属性 一.类的定义 Swift与Objective-C定义类的区别 Objective-C:一般需要2个文件,1个.h声明文件和1个.m实现文件 Swift:只需要 ...
- 如何实现 iOS 自定义状态栏
给大家介绍如何实现 iOS 自定义状态栏 Sample Code: 01 UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIAp ...
随机推荐
- PHP之闭包详解
匿名函数提到闭包就不得不想起匿名函数,也叫闭包函数(closures),貌似PHP闭包实现主要就是靠它.声明一个匿名函数是这样: $func = function() { }; //带结束符 可以看到 ...
- python教程,文章list
http://www.2cto.com/kf/web/Python/ http://www.v2ex.com/go/python http://www.sharejs.com/codes/python ...
- centos6.5vpn搭建
centos6.5vpn搭建整个搭建流程,服务端,客户端安装及测试. 达到的效果: 在安装vpn客户端的机器可通过vpn(virtual private network)专用线路(vpn主配置文件中定 ...
- SQL高级查询
高级查询: 一.多表链接 1,普通查询 select * from 表名,表名 where 表名.列名 = 表名.列名 2,join链接 select * from 表名 join 表名 on 表名. ...
- Android建立模拟器进行调试
安装好android开发环境后.用到下面几个命令.android, adb, emulator android - 最主要的android命令.能够进行sdk更新,列出设备源,生成虚拟设备等. adb ...
- NSJSONSerialization(category)的一个扩展类
.h文件 // // NSJSONSerialization+Manage.h // SVPullToRefreshDemo // // Created by Fuer on 14-7-4. // C ...
- OracleOraDb10g_home1TNSListener服务无法启动
启动OracleOraDb10g_home1TNSListener服务的时候就报错:“Windows无法启动OrcleOraDb11g_home1TNSListener服务(位于本地计算机上). 错误 ...
- LayoutInflater作用及使用
作用: 1.对于一个没有被载入或者想要动态载入的界面, 都需要使用inflate来载入. 2.对于一个已经载入的Activity, 就可以使用实现了这个Activiyt的的findViewById方法 ...
- leetcode Longest Common Prefix python
class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str ...
- MySql按指定天数进行分组数据统计分析 2
上次的随笔1中写的分组方式,经分析,是从前往后进行分组,即若选择2014的数据进行统计每11天为一组的话,1的分组方式, 按照2014-01-01——2014-01-11为一组,之后每11天为一组. ...