转自:http://blog.csdn.net/jinglijun/article/details/7259729
//CustomNavigationBar.h
#import <UIKit/UIKit.h>
@interface UINavigationBar (UINavigationBarCategory)
- (void)setBackgroundImage:(UIImage*)image;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
@end
//CustomNavigationBar.m
#import "CustomNavigationBar.h"
@implementation UINavigationBar (UINavigationBarCategory)
UIImageView *backgroundView;
-(void)setBackgroundImage:(UIImage*)image
{
if(image == nil)
{
[backgroundView removeFromSuperview];
}
else
{
backgroundView = [[UIImageView alloc] initWithImage:image];
backgroundView.tag = 1;
backgroundView.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height);
backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:backgroundView];
[self sendSubviewToBack:backgroundView];
[backgroundView release];
}
}
//for other views
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
{
[super insertSubview:view atIndex:index];
[self sendSubviewToBack:backgroundView];
}
@end
//YourViewController.m
#import "CustomNavigationBar.h"
//判断设备的版本
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
//ios5 新特性
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"titleBar.png"] forBarMetrics:UIBarMetricsDefault];
}
#endif
分享到:
相关推荐
代码受https://github.com/ltebean/LTNavigationBar/启发,将其Objective-C的代码更改为swift代码,实现了UINavigationBar的扩展,代码调用非常简单,只需要一句话即可实现导航栏的颜色变更,十分适合需要做个性化...
解决UINavigationBar 自定义 leftBarButtonItem 点击范围过大的问题
自定义系统UINavigationBarController,支持多种效果。 1.全透明样式 2.不透明效果(和全局统一) 3.自定义颜色 4.滑动渐变样式 5.滑动动画样式
自定义UINavigationBar。自定义导航条,包括颜色、图片以及上面的按钮。在iOS5.0以上版本,要想navigation bar上面也能显示木质图片,要更改“WoodUINavigationAppDelegate.m”文件的一段代码:...
UINavigationBar不同颜色的过度 github地址:https://github.com/Liqiankun/DLNavigationBar
通过手势来返回上一页。也可以通过左上角按钮返回。UINavigationBar自定义的
网上有很多关于隐藏的方法,设置后能够成功,但是跳转到其他界面的时候发现,其他界面横线也被隐藏了。 目前主流的方法是将shadowImage用一张空的图片图片替换掉 可是这种方法不能解决navigationController里面的...
用swift写的一个UINavigationBar的扩展,总结可3种隐藏UINavigationBar的方式,代码的github下载地址:https://github.com/631106979/WCLHideNavBar,代码详解的博客地址:...大家觉得学到东西的可以给点个赞,有什么...
Android 仿 iOS UINavigationBar 风格的 Titlebar,适用于某些 UI 设计师只出 iOS 效果图的项目
一个像微信那样有追求的 UINavigationBar, 阴影,透明度,是否隐藏,背景颜色平滑过渡。兼容来电模式,兼容 到 iOS 8。 详情请移步 GitHub: https://github.com/listenzz/HBDNavigationBar
雨松MOMO 《IOS入门开发系列专题》 IOS 入门开发之创建标题栏UINavigationBar的使用(二) 欢迎大家下载阅读,哇咔咔。
具有iOS的Google Material样式的自定义UINavigationBar 演示/范例 对于演示: $ pod try MaterialNavbar 要运行示例项目,请克隆存储库,然后首先从Example目录运行pod install 。 $ cd Example $ pod install ...
在iOS上具有渐变颜色的自定义UINavigationBar子类。 截屏 要求 iOS SDK 7.0或更高版本 安装 将以下行添加到您的Podfile中: pod "JXGradientNavigationBar" 用法 导入头文件: # import " ...
UINavigationBar 是每一个 iOS 工程师都会遇到的坎,它令人抓狂的地方在于是否能随着页面切换而平滑地过渡到目的状态。想要把这件事情做好,不需要高深的算法,不需要深刻的底层原理,只需要一颗执着的内心。 介绍 ...
自定义UINavigationBar。自定义导航条的按钮,包括增加按钮、segments等等。在导航条左边、中间、右边增加按钮或其他控件。 注意:请在Mac下解压使用
这是一个小示例应用程序,显示了如何自定义导航页(Android上为工具栏或iOS上为UINavigationBar),此示例是针对StackOverflow中的一个问题,您可以在此处看到此问题: 使用C#6功能构建,必须运行VS 2015或VS 2017...
RRMaterialNavigationBar 自定义 UINavigationBar 与 Google Material 风格,动画非常流畅。 它专为使用 Swift 编写的 iOS 而设计。 RRNavigationBar是 UINavigationBar 的子类,所以你可以像往常一样使用它。 对于 ...
主要为大家详细介绍了iOS开发tips-UINavigationBar的切换效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
为UINavigationBar添加自定义背景 15 加载图片要及时release 15 uiwebview打开doc,pdf文件 16 iPhone游戏中既播放背景音乐又播放特效声音的办法 16 NSNotificationCenter用于增加回调函数 17 UINavigationBar 背景...