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 ...
随机推荐
- NOI2014 Day1
NOI2014 Day1 起床困难综合症 题目描述:给出\(n\)个操作,每个操作包含一种运算\((XOR.OR.AND)\)和一个数,已知一开始的数字为\([0, m]\),问经过\(n\)次操作后 ...
- centos6 qt ENV
打算做嵌入式图像处理,计划方案嵌入式Linux+OpenCV+QT,昨天简单入门OpenCV今天看看QT,QT就先弄Linux下面的,回家之前争取把基本的摸通,然后能在板子上跑起来 关于QT安装 QT ...
- oracle初始安装大小
oracle初始安装大小 /ruiy/ocr/DBSoftware/app/oracle/ruiy/ocr/DBSoftware/app/oraInventory/ruiy/ocr/DBData/or ...
- S3C6410嵌入式应用平台构建(二)
[2014-4/11~4/14]经过之前的实验,对Uboot已经有了大体的了解,前我们已经把led灯给点亮,但这不是我们的根本目的,我们是要进入boot启动,经过两天的分析代码和反复的实验,终于可以进 ...
- LeetCode第四题,Add Two Numbers
题目原文: You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- 通过案例练习掌握SSH 的整合
1. SSH整合_方案01 ** 整合方案01 Struts2框架 Spring框架 在Spring框架中整合了Hibernate(JDBC亦可) 一些业务组件(Service组件)也可以放入 ...
- SQL数据库插入文本信息
文本内容
- ADO.NET FOR MySQL帮助类
using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...
- 获取 web容器中的bean
public class WebContextBeanFinder { public static Object getBean(String beanId) { ServletContext ser ...
- Nio Client
public class NIOClient { static int SIZE = 2; final static int bufferSize = 500 * 1024; static InetS ...