IOS 设置导航栏全局样式
- // 1.设置导航栏背景
- UINavigationBar *bar = [UINavigationBar appearance];
- [bar setBackgroundImage:[UIImage resizeImage:@"NavigationBar_Background.png"] forBarMetrics:UIBarMetricsDefault];
- // 状态栏
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
- // 2.设置导航栏文字属性
- NSMutableDictionary *barAttrs = [NSMutableDictionary dictionary];
- [barAttrs setObject:[UIColor darkGrayColor] forKey:UITextAttributeTextColor];
- [barAttrs setObject:[NSValue valueWithUIOffset:UIOffsetMake(0, 0)] forKey:UITextAttributeTextShadowOffset];
- [bar setTitleTextAttributes:barAttrs];
- // 3.按钮
- UIBarButtonItem *item = [UIBarButtonItem appearance];
- [item setBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Normal.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- [item setBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Pressed.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
- NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionaryWithDictionary:barAttrs];
- [itemAttrs setObject:[UIFont boldSystemFontOfSize:13] forKey:UITextAttributeFont];
- [item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
- [item setTitleTextAttributes:itemAttrs forState:UIControlStateHighlighted];
- [item setTitleTextAttributes:itemAttrs forState:UIControlStateDisabled];
- // 4.返回按钮
- [item setBackButtonBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Back_Normal.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- [item setBackButtonBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Back_Pressed.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
搞了半天,居然没有发现可以插入Objective-C代码的地方。真郁闷
- //
- // UIImage+Fit.m
- // SinaWeibo
- //
- // Created by mj on 13-8-19.
- // Copyright (c) 2013年 itcast. All rights reserved.
- //
- #import "UIImage+Fit.h"
- @implementation UIImage (Fit)
- #pragma mark 返回拉伸好的图片
- + (UIImage *)resizeImage:(NSString *)imgName {
- return [[UIImage imageNamed:imgName] resizeImage];
- }
- - (UIImage *)resizeImage
- {
- CGFloat leftCap = self.size.width * 0.5f;
- CGFloat topCap = self.size.height * 0.5f;
- return [self stretchableImageWithLeftCapWidth:leftCap topCapHeight:topCap];
- }
- - (UIImage *)cut:(CGSize)sizeScale
- {
- CGFloat width = self.size.width * sizeScale.width;
- CGFloat height = self.size.height * sizeScale.height;
- CGFloat x = (self.size.width - width) * 0.5;
- CGFloat y = (self.size.height - height) * 0.5;
- CGRect rect = CGRectMake(x, y, width, height);
- CGImageRef ref = CGImageCreateWithImageInRect(self.CGImage, rect);
- return [UIImage imageWithCGImage:ref];
- }
- @end
IOS 设置导航栏全局样式的更多相关文章
- iOS设置导航栏样式(UINavigationController)
//设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...
- IOS 设置导航栏
//设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...
- iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...
- iOS 设置导航栏的颜色和导航栏上文字的颜色
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- iOS 设置导航栏全透明
- (void)viewWillAppear:(BOOL)animated{ //设置导航栏背景图片为一个空的image,这样就透明了 [self.navigationController.navig ...
- ios 设置导航栏背景色
//设置导航栏背景色 如果上面的不好用 就用下面的 [self.navigationController.navigationBar setBackgroundImage:[UIImage image ...
- IOS设置导航栏字体大小及颜色
方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...
- iOS设置导航栏标题
方法一:在UIViewController中设置self.title. 方法二:设置self.navigationItem.titleView.
- iOS设置导航栏透明度
As I support Colin's answer, I want to give you an additional hint to customize the appearance of an ...
随机推荐
- iOS截屏
- (UIImage *)captureImageFromView:(UIView *)view{ UIGraphicsBeginImageContext(view.bounds.size); CGC ...
- 无后台的网站 内容暂存json
当网站无后台时,将数据暂存储为json文档,然后通过调用json文件获取数据填充前端页面 存储json格式的文件 [ { "id": 1, "cat": &qu ...
- 通过BroadCast与service时时监听网络变化
首先需要一个service: 这里我定义了一个NetworkStateService,在这个service中我写了一个BroadcastReceiver用于监听网络状态发生改变的情况并在这个servi ...
- 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 ...
- angular2-aot-webpack 生产环境下编译angular2
这里讲讲,angular2在生产模式下用webpack2进行打包的方法: //使用rollup打包还是比较坑的,功能及插件上都不如webpack, 关键不支持代码分离,导致angular里的lazy ...
- windows 7 右下角登陆信息去除
---恢复内容开始--- 开始--运行中输入regedit 找到注册表键值HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NlaSvc\Par ...
- 每天一个命令ls 2015/4/1
ls命令可以说是Linux下最常用的命令 -a 列出目录下的所有文件,包括以 . 开头的隐含文件.-b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出.-c 输出文件的 i ...
- C# 模拟按下回车键自动登录
private void Form1_Load(object sender, EventArgs e) { //this.Show(); this.Activate(); //this.Focus() ...
- SQL语句小总结
无论是面试过程中,还是未来工作中,SQL都是一定会考到和用到的.所以,在此对之前看过的一些SQL知识点进行一下总结和记录,算是起到一个笔记本的作用.没有深入学习过SQL的和对SQL印象不太深的朋友可以 ...
- FreeBSD Opera Flash问题
环境:FreeBSD 10,Opera,kldload linux 有些地方还是需要 flash 阿,但按照 Handbook 里面安装了 linux-f10-flashplugin11 和 oper ...