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 ...
随机推荐
- 影响世界的IT
MIT BBS上说微软电话面试的一道题就是"Who do you think is the best coder,and why?”.我觉得挺有意思的,也来凑个热闹.排名不分先后. 1.Bi ...
- 转: HTML5新特性之Mutation Observer
转: HTML5新特性之Mutation Observer Mutation Observer是什么 Mutation Observer(变动观察器)是监视DOM变动的接口.当DOM对象树发生任何变动 ...
- 将String类型的数字字符转换成int
java.lang.Integer.parseInt(String) public static int parseInt(String s) throws NumberFormatException ...
- 今天起改用mac的marsedit写博
最近一直使用mac来工作,所以写博也相应改为marsedit. 初步感觉还是不错的,越来越发现mac其实也适合在工作中使用,生活上当然不在话下. 从高富帅的x220t变成屌丝的macbook小白(升级 ...
- ebs清除并法管理器所清除的表
In this Document Goal Solution References Applies to: Oracle Concurrent Processing - Version 1 ...
- CouchDB简单应用
CouchDB是众多称作NoSQL解决方案中的一员.与众不同的是,CouchDB是一个面向文档的数据库,在它里面所有文档域(Field)都是以键值对的形式存储的.域(Field)可以是一个简单的键值对 ...
- MATLAB中imshow()和image()
MATLAB中imshow()和image(): IMSHOW Display image in Handle Graphics figure. IMSHOW(I) displays the gray ...
- malloc 申请得到的内存后,再 free 释放它的时候,操作系统会立即收回那块内存吗?
stackoverflow上的回答: In many malloc/free implementations, free does normally not return the memory to ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- 请求http服务
①服务方法 [HttpGet]//get服务 public JsonResult GetUserName(int id) { try { IXiao_UserBLL bll = new Xiao_Us ...