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 ...
随机推荐
- 排序-java
今天座右铭----每天的学习会让我们不断地进步! 往往面试中都会让我们用一种排序方法做一道排序题,下面我就罗列出快速排序.冒泡排序.插入排序.选择排序的java代码! 1.快速排序 public cl ...
- centos ldap
Standalone LDAP Daemon, slapd(standalone lightweight access protocol)Lightweight Directory Access Pr ...
- display的table和cell外加table-layout:fixed等分布局,外加换行,word-wrap:break-word
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#Base64加密
using System;using System.Collections.Generic;using System.Text;using System.Security.Cryptography;u ...
- webService接口大全
中文<->英文双向翻译WEB服务 获得标准数据 Endpoint: http://fy.webxml.com.cn/webservices/EnglishChinese.asmx Disc ...
- Mysql 批量杀死进程
正常情况下kill id,即可,但是有时候某一异常连接特别多的时候如此操作会让人抓狂,下面记录下小方法: use information_schema; select concat('kill ',i ...
- 为什么Java项目前会出现一个红色感叹号!
先看看问题,如下图所示: 造成这个问题的原因是,我把一个 jar 包删除了,然后又配了个新的进去,然后就一直有这个错误,刚开始很郁闷,怎么已经配置过儿,还出现这个问题?关键是代码里面没有报错的.郁闷的 ...
- Android中计算时间差的实现方法
今天为“至简天气”增加了一项功能:在启动时根据上次更新数据的时间判断是否有必要更新数据,因为 weather.com.cn 的实况数据貌似是25分钟才会刷新一次,只有在据上次更新的时间达25分钟以上才 ...
- MySQL 二进制日志过滤
binlog_do_db; binlog_ignore_db; 这个两个参数是用来控制对哪个数据库的更改要记录日志:下面以binlog_ignore_db为例子. 假如binlog_ignore_db ...
- Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本
说明: 1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是 ...