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. ipython安装

    sudo pip install jupyter 然后用jupyter notebook来运行

  2. jsp基础知识

  3. js/css在html文档中的引用外部文件方式对比

    包含css样式表和js脚本的最好方式是使用外部文件,因为css/js和html标记文档可以清晰地分离. css的外部引用写在<head></head>中: <head&g ...

  4. MSXML应用总结

    MSXML的DOM模型是符合W3C DOM标准的,而DOM API在Windows中以COM接口的形式提供,关于COM请大家查阅相关资料.简单来说,COM提供了一个环境和一套规则,使接口的设计实现到对 ...

  5. (转)Three challenges you’re going to face when building a chatbot

        转自:https://blog.infermedica.com/three-challenges-youre-going-to-face-when-building-a-chatbot/   ...

  6. Servlet,jsp,JSP技术 ,JSP编程

     一.Servlet 思考 1 浏览器可以直接打开JAVA/class文件吗? 不可以 2浏览器可以打开HTML.JS 文件吗? 可以 3 JAVA程序可以生成HTML文件吗?可以的,用IO流. 4 ...

  7. ubuntu包管理

    查看某个文件属于哪个包dpkg -S add-apt-repository 包名software-properties-common命令名/usr/bin/add-apt-repository/usr ...

  8. 数据库中Schema和Database有什么区别

    在MySQL中创建一个Schema好像就跟创建一个Database是一样的效果,在SQL Server和Orcal数据库中好像又不一样. 目前我只能理解,在mysql中 schema<==> ...

  9. Python os._exit() sys.exit()

    os._exit()会直接将python程序终止,之后的所有代码都不会继续执行. sys.exit()会引发一个异常:SystemExit,如果这个异常没有被捕获,那么python解释器将会退出.如果 ...

  10. mybatis 与 缓存

    首先从配置文件说起,有个cacheEnabled的配置项,当设置为true时(默认就是true),Session就会用一个CachingExecutor来包装我们的Executor实例: public ...