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 ...
随机推荐
- ipython安装
sudo pip install jupyter 然后用jupyter notebook来运行
- jsp基础知识
- js/css在html文档中的引用外部文件方式对比
包含css样式表和js脚本的最好方式是使用外部文件,因为css/js和html标记文档可以清晰地分离. css的外部引用写在<head></head>中: <head&g ...
- MSXML应用总结
MSXML的DOM模型是符合W3C DOM标准的,而DOM API在Windows中以COM接口的形式提供,关于COM请大家查阅相关资料.简单来说,COM提供了一个环境和一套规则,使接口的设计实现到对 ...
- (转)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/ ...
- Servlet,jsp,JSP技术 ,JSP编程
一.Servlet 思考 1 浏览器可以直接打开JAVA/class文件吗? 不可以 2浏览器可以打开HTML.JS 文件吗? 可以 3 JAVA程序可以生成HTML文件吗?可以的,用IO流. 4 ...
- ubuntu包管理
查看某个文件属于哪个包dpkg -S add-apt-repository 包名software-properties-common命令名/usr/bin/add-apt-repository/usr ...
- 数据库中Schema和Database有什么区别
在MySQL中创建一个Schema好像就跟创建一个Database是一样的效果,在SQL Server和Orcal数据库中好像又不一样. 目前我只能理解,在mysql中 schema<==> ...
- Python os._exit() sys.exit()
os._exit()会直接将python程序终止,之后的所有代码都不会继续执行. sys.exit()会引发一个异常:SystemExit,如果这个异常没有被捕获,那么python解释器将会退出.如果 ...
- mybatis 与 缓存
首先从配置文件说起,有个cacheEnabled的配置项,当设置为true时(默认就是true),Session就会用一个CachingExecutor来包装我们的Executor实例: public ...