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. iOS截屏

    - (UIImage *)captureImageFromView:(UIView *)view{ UIGraphicsBeginImageContext(view.bounds.size); CGC ...

  2. 无后台的网站 内容暂存json

    当网站无后台时,将数据暂存储为json文档,然后通过调用json文件获取数据填充前端页面 存储json格式的文件 [ { "id": 1, "cat": &qu ...

  3. 通过BroadCast与service时时监听网络变化

    首先需要一个service: 这里我定义了一个NetworkStateService,在这个service中我写了一个BroadcastReceiver用于监听网络状态发生改变的情况并在这个servi ...

  4. eclipse Run On Server 异常:could not load the Tomcat Server configuration at Servers\tomcat V5.0 Sertomcat

    eclipse Run On Server 异常:could not load the Tomcat Server configuration at Servers\tomcat V5.0 Serto ...

  5. angular2-aot-webpack 生产环境下编译angular2

    这里讲讲,angular2在生产模式下用webpack2进行打包的方法: //使用rollup打包还是比较坑的,功能及插件上都不如webpack, 关键不支持代码分离,导致angular里的lazy ...

  6. windows 7 右下角登陆信息去除

    ---恢复内容开始--- 开始--运行中输入regedit 找到注册表键值HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NlaSvc\Par ...

  7. 每天一个命令ls 2015/4/1

    ls命令可以说是Linux下最常用的命令 -a 列出目录下的所有文件,包括以 . 开头的隐含文件.-b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出.-c 输出文件的 i ...

  8. C# 模拟按下回车键自动登录

    private void Form1_Load(object sender, EventArgs e) { //this.Show(); this.Activate(); //this.Focus() ...

  9. SQL语句小总结

    无论是面试过程中,还是未来工作中,SQL都是一定会考到和用到的.所以,在此对之前看过的一些SQL知识点进行一下总结和记录,算是起到一个笔记本的作用.没有深入学习过SQL的和对SQL印象不太深的朋友可以 ...

  10. FreeBSD Opera Flash问题

    环境:FreeBSD 10,Opera,kldload linux 有些地方还是需要 flash 阿,但按照 Handbook 里面安装了 linux-f10-flashplugin11 和 oper ...