A.导航栏两侧文字按钮
1.需求:
所有导航栏两侧的文字式按钮统一样式
普通样式:橙色
高亮样式:红色
不可用样式:亮灰
阴影:不使用
字体大小:15
 
 
2.实现效果
默认样式:
 
统一使用样式:
 
3.思路
  • 在创建item的时候逐个设置:代码超级冗余
  • 抽取创建公共父类:稍好的选择,但是继承了此公共父类的控制器,就不能操作其去继承系统自带的控制器类了,造成很大的隐患。iOS中控制器不建议提取公共父类,最好直接继承系统自带控制器。
  • 使用主题appearance统一设置所有UIBarButtonItem的样式:采用!在自定义的UINavigationController的类初始化方法中实现一次,就可以改变所有使用了此类的BarButtonItem样式
 
4.实现
HVWNavigationViewController.m:
 /** 类初始化的时候调用 */
+ (void)initialize {
// 初始化导航栏样式
[self initNavigationBarTheme]; // 初始化导航栏item样式
[self initBarButtonItemTheme];
} /** 统一设置导航栏item的样式
* 因为是通过主题appearence统一修改所有NavivationBar的样式,可以使用类方法
*/
+ (void) initBarButtonItemTheme {
// 设置导航栏,修改所有UINavigationBar的样式
UIBarButtonItem *appearance = [UIBarButtonItem appearance]; // 设置noraml状态下的样式
NSMutableDictionary *normalTextAttr = [NSMutableDictionary dictionary];
// 字体大小
normalTextAttr[NSFontAttributeName] = [UIFont systemFontOfSize:];
// 字体颜色
normalTextAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];
// 设置为normal样式
[appearance setTitleTextAttributes:normalTextAttr forState:UIControlStateNormal]; // 设置highlighted状态下的样式
NSMutableDictionary *highlightedTextAttr = [NSMutableDictionary dictionaryWithDictionary:normalTextAttr];
// 字体颜色
highlightedTextAttr[NSForegroundColorAttributeName] = [UIColor redColor];
// 设置为normal样式
[appearance setTitleTextAttributes:highlightedTextAttr forState:UIControlStateHighlighted]; // 设置disabled状态下的样式
NSMutableDictionary *disabledTextAttr = [NSMutableDictionary dictionaryWithDictionary:normalTextAttr];
// 字体颜色
disabledTextAttr[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
// 设置为normal样式
[appearance setTitleTextAttributes:disabledTextAttr forState:UIControlStateDisabled]; }
 
B.设置导航栏样式
1.需求:
  • 统一显示文字颜色:黑色
  • 文字阴影:禁止
  • 字体大小:20
 
 
2.思路:同“A”
 
3.实现:
同“A"
HVWNavigationViewController.m:
 /** 统一设置导航栏样式 */
+ (void) initNavigationBarTheme {
// 使用appearence(主题)设置,统一修改所有导航栏样式
UINavigationBar *appearance = [UINavigationBar appearance]; // 为了统一iOS6和iOS7,iOS6需要设置导航栏背景来模拟iOS7的效果
if (!iOS7) {
[appearance setBackgroundImage:[UIImage imageWithNamed:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
} // 设置属性
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
// 设置字体
attr[NSForegroundColorAttributeName] = [UIColor blackColor];
attr[NSFontAttributeName] = [UIFont systemFontOfSize:];
// 消去文字阴影,设置阴影偏移为0
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeZero;
attr[NSShadowAttributeName] = shadow; [appearance setTitleTextAttributes:attr];
}
 

[iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)的更多相关文章

  1. IOS开发中设置导航栏主题

    /** * 系统在第一次使用这个类的时候调用(1个类只会调用一次) */ + (void)initialize { // 设置导航栏主题 UINavigationBar *navBar = [UINa ...

  2. [iOS微博项目 - 4.3] - 设置每条微博边框样式

    github: https://github.com/hellovoidworld/HVWWeibo A.设置每条微博边框样式 1.需求 不需要分割线 每个微博之间留有一定的间隙   2.思路 直接设 ...

  3. [iOS微博项目 - 4.2] - 设置转发微博背景

    github: https://github.com/hellovoidworld/HVWWeibo A.转发微博部分的淡灰色背景 1.需求 转发微博部分需要设置背景色 使用图片作为背景   2.思路 ...

  4. 美团HD(1)-设置导航栏主题

    自定义一个UINavigationController DJNavigationController.h #import <UIKit/UIKit.h> @interface DJNavi ...

  5. iOS导航栏主题

    主要是取得导航栏的appearance对象,操作它就设置导航栏的主题 UINavigationBar *navBar = [UINavigationBar appearance]; 常用主题设置 导航 ...

  6. iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)

    一.UI_APPEARANCE_SELECTOR 彩票项目中appearance的用法一直没有搞明白,这次通过第二个项目中老师的讲解,更深一层次的了解到了很多关于appearance的作用以及使用方法 ...

  7. 【转】iOS中设置导航栏标题的字体颜色和大小

    原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...

  8. iOS中设置导航栏标题的字体颜色和大小

    iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...

  9. IOS 设置导航栏

    //设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...

随机推荐

  1. C/C++内存存储

    #include <stdio.h> #include "string.h" #include "malloc.h" void Swap(int a ...

  2. tc 2014 college tour 250 500

    题意: You are given a long long n. Return the largest divisor of n that is a perfect square. That is, ...

  3. Ural1076(km算法)

    题目大意 给出n*n表格,第a[i,j]表示i到j的权值,现在我们要将每个a[i,j]=sum[j]-a[i,j], 求出当前二分图a[][]最小匹配 最小匹配只需将权值取负后,求二分图最大匹配,使用 ...

  4. 基于XMPP的即时通信系统的建立(四)— 组件介绍

    服务端 服务器 许可证 操作系统 是否支持任意客户端登录 备注 ejabberd 开源 Elang 是 支持虚拟主机和集群 Openfire Apache Java 是 Tigase GPLv3 Ja ...

  5. UVa 11489 (博弈) Integer Game

    一个数字能被3整除就等价于这个数的各个数字之和被3整除. 所以一开始的时候先要拿一个能使剩下的数字是3的倍数的数. 然后就一直拿0.3.6.9直到某人不能再拿为止. #include <cstd ...

  6. Android-Universal-Image-Loader

    基本以后都不用了,所以自己就不总结了 http://www.cnblogs.com/kissazi2/p/3886563.html http://www.cnblogs.com/kissazi2/p/ ...

  7. win7x64下的redis安装与使用

    先引用百度百科的一段话吧,具体可以到百科查看吧. Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年 ...

  8. Android下高斯模糊的算法和demo

    采用纯java和RenderScript两种方式来做高斯算法. 也可以用NDK来做,想试试的可以参考: http://stackoverflow.com/questions/2067955/fast- ...

  9. 【DFS】NYOJ-82 迷宫寻宝(一)-条件迷宫问题

    [题目链接:NYOJ-82] #include<iostream> #include<cstring> using namespace std; struct node{ in ...

  10. android moveTaskToback 应用退到后台,类似最小化

    方法:public boolean moveTaskToBack(boolean nonRoot) activity里有这个方法,参数说明如下: nonRoot=false→ 仅当activity为t ...