1. // 1.设置导航栏背景
  2. UINavigationBar *bar = [UINavigationBar appearance];
  3. [bar setBackgroundImage:[UIImage resizeImage:@"NavigationBar_Background.png"] forBarMetrics:UIBarMetricsDefault];
  4. // 状态栏
  5. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
  6. // 2.设置导航栏文字属性
  7. NSMutableDictionary *barAttrs = [NSMutableDictionary dictionary];
  8. [barAttrs setObject:[UIColor darkGrayColor] forKey:UITextAttributeTextColor];
  9. [barAttrs setObject:[NSValue valueWithUIOffset:UIOffsetMake(0, 0)] forKey:UITextAttributeTextShadowOffset];
  10. [bar setTitleTextAttributes:barAttrs];
  11. // 3.按钮
  12. UIBarButtonItem *item = [UIBarButtonItem appearance];
  13. [item setBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Normal.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  14. [item setBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Pressed.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  15. NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionaryWithDictionary:barAttrs];
  16. [itemAttrs setObject:[UIFont boldSystemFontOfSize:13] forKey:UITextAttributeFont];
  17. [item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
  18. [item setTitleTextAttributes:itemAttrs forState:UIControlStateHighlighted];
  19. [item setTitleTextAttributes:itemAttrs forState:UIControlStateDisabled];
  20. // 4.返回按钮
  21. [item setBackButtonBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Back_Normal.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  22. [item setBackButtonBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Back_Pressed.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

搞了半天,居然没有发现可以插入Objective-C代码的地方。真郁闷

  1. //
  2. //  UIImage+Fit.m
  3. //  SinaWeibo
  4. //
  5. //  Created by mj on 13-8-19.
  6. //  Copyright (c) 2013年 itcast. All rights reserved.
  7. //
  8. #import "UIImage+Fit.h"
  9. @implementation UIImage (Fit)
  10. #pragma mark 返回拉伸好的图片
  11. + (UIImage *)resizeImage:(NSString *)imgName {
  12. return [[UIImage imageNamed:imgName] resizeImage];
  13. }
  14. - (UIImage *)resizeImage
  15. {
  16. CGFloat leftCap = self.size.width * 0.5f;
  17. CGFloat topCap = self.size.height * 0.5f;
  18. return [self stretchableImageWithLeftCapWidth:leftCap topCapHeight:topCap];
  19. }
  20. - (UIImage *)cut:(CGSize)sizeScale
  21. {
  22. CGFloat width = self.size.width * sizeScale.width;
  23. CGFloat height = self.size.height * sizeScale.height;
  24. CGFloat x = (self.size.width -  width) * 0.5;
  25. CGFloat y = (self.size.height - height) * 0.5;
  26. CGRect rect = CGRectMake(x, y, width, height);
  27. CGImageRef ref = CGImageCreateWithImageInRect(self.CGImage, rect);
  28. return [UIImage imageWithCGImage:ref];
  29. }
  30. @end

IOS 设置导航栏全局样式的更多相关文章

  1. iOS设置导航栏样式(UINavigationController)

    //设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...

  2. IOS 设置导航栏

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

  3. iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)

                      #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...

  4. iOS 设置导航栏的颜色和导航栏上文字的颜色

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  5. iOS 设置导航栏全透明

    - (void)viewWillAppear:(BOOL)animated{ //设置导航栏背景图片为一个空的image,这样就透明了 [self.navigationController.navig ...

  6. ios 设置导航栏背景色

    //设置导航栏背景色 如果上面的不好用 就用下面的 [self.navigationController.navigationBar setBackgroundImage:[UIImage image ...

  7. IOS设置导航栏字体大小及颜色

    方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...

  8. iOS设置导航栏标题

    方法一:在UIViewController中设置self.title. 方法二:设置self.navigationItem.titleView.

  9. iOS设置导航栏透明度

    As I support Colin's answer, I want to give you an additional hint to customize the appearance of an ...

随机推荐

  1. junit单元测试(keeps the bar green to keeps the code clean)

    error是程序错误,failure是测试错误. junit概要: JUnit是由 Erich Gamma (设计模式的创始人)和 Kent Beck (敏捷开发的创始人之一)编写的一个回归测试框架( ...

  2. help man info 三个的区别

    “--help”选项 “--help”是一个工具选项,大部分的GNU工具都具备这个选项,“--help”选项可以用来显示一些工具的信息 “man”工具 Man工具可以显示系统手册页中的内容,这些内容大 ...

  3. Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...

  4. Python列表

    列表不同于字符串和元组:列表是可变的--可以改变列表的内容 1.列表函数 1.list(x)函数(其实是一种类型,而不是一个真正意义上的函数) 转化为列表,其中x可以是其他序列 可以用''.join( ...

  5. 开始写Effective系列总结一些前端的心得

    确实是没有时间整理以及总结和发表自己的感慨.难得中秋银行的事情搞完了自己清闲3天,是时候总结一下从大公司做.NET PC 端网站的开发到现在做移动互联网的银行及政府微信公众号的开发的感触.当时自己的选 ...

  6. h5调用摄像头

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...

  7. python 模拟用户登录代码

    需求:输入用户名,判断用户是否被锁定,锁定则退出,否则进入密码验证,输入三次错误密码之后此用户被锁定. userlist.txt里,用":"将用户名.密码.状态码分开: [root ...

  8. Could not load java.net.BindException错误解决

    出现了错误异常:信息: Illegal access: this web application instance has been stopped already.  Could not load ...

  9. SSH基于Hibernate eventListener 事件侦听器的操作日志自动保存到数据库

    在spring xml配置文件中添加配置,包含:model.listener 在model中增加需要写入数据库对应表的model 在auditLog.xml配置文件中配置自己项目中,需要进行日志记录的 ...

  10. 64位系统里的IIS运行32位ODP.NET的方法

    在64位Win7里的IIS里部署使用了ODP.NET的网站,Oracle的版本是11.20.3.20.直接部署会提示错误:在64位环境里使用了32位的程序.自己折腾了两天,最后才从别人的博客里找到解决 ...