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系统(苹果手机)按钮显示为圆角和渐变的问题

    按钮在安卓手机上显示正常,但在苹果手机上会显示如下: 解决办法:给该按钮的样式加上:-webkit-appearance:none;这样按钮就会显示正常

  2. Linux虚拟机安装(CentOS 6.5,图文详解,需要自查)

    Linux虚拟机的安装(图文详解) 下篇会接续Hadoop集群安装(以此为基础) 一.安装准备 VMWorkstation.linux系统镜像(以下以CentOS6.5为例) 二.安装过程详解 关闭防 ...

  3. jquery常用选择器和常用方法

    基本选择器 $(”#myDiv”) //匹配唯一的具有此id值的元素 $(”div”) //匹配指定名称的所有元素 $(”.myClass”) //匹配具有此class样式值的所有元素 $(”*”) ...

  4. HDU 1010 Tempter of the Bone(深度+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...

  5. 关于js代码中与或运算符||&&的妙用

    看bootstrap时看到如下一行JavaScript代码产生了疑惑. return window.pageYOffset || e.scrollTop ||在这里的作用是什么呢? 首先明确概念,在j ...

  6. etcd第三集

    简单说下golang的etcd接口例子.etcd api有v2(http+json)和v3(grpc)两个版本,目前大家都用v2,所以... v2: https://github.com/coreos ...

  7. WPF 重新启动该程序

    // Restart current process Method 1 System.Windows.Forms.Application.Restart(); Application.Current. ...

  8. notepad++

    plugin-manager 先要保证plugin-manager是最新的,然后才能下载其它的插件进行安装. compare插件,文件对比工具

  9. 在datagrid中实现单击行选择整行

    首先添加列:<asp:ButtonColumn Text="选择" CommandName="Select" Visible="False&qu ...

  10. ArcEngine :The XY domain on the spatial reference is not set or invalid错误

    在创建数据集的时候,提示The XY domain on the spatial reference is not set or invalid错误. 原因:未设置空间参考(ISpatialRefer ...