UINavigationBar添加背景图片
代码修改如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
_nav = [[UINavigationController alloc] initWithRootViewController:_rootViewController];
UIImage *backgroundImage = [UIImage imageNamed:@"NaviBackground.png"];
[self setNavigationBarBackgroundImage:backgroundImage];
[self.window setRootViewController:_nav];
[self.window makeKeyAndVisible];
returnYES;
}
- (void)setNavigationBarBackgroundImage:(UIImage *)backgroundImage
{
UINavigationBar *navBar = [_nav navigationBar];
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
else {
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];
if (imageView == nil) {
imageView = [[UIImageView alloc] initWithImage:backgroundImage];
[imageView setTag:kSCNavBarImageTag];
[navBar insertSubview:imageView atIndex:0];
[imageView release];
}
}
}
参考:
Adding a Background Image to UINavigationBar
An Introduction To UINavigationController
学习笔记:UINavigationController使用详解
转载于:https://www.cnblogs.com/StarMud/archive/2012/11/30/2796397.html
a2614555 原创文章 0获赞 0访问量 209 关注 私信- 为UINavigationBar添加背景图片的几种简单思路
- UINavigationBar添加背景图片的几种简单思路
- unity3D 添加背景图片
- QT Creator创建菜单,添加图标和背景图片
- MFC对话框添加背景图片
- 网站背景图片添加
- iOS----如何添加背景图片 并使图片可以一直在背景中显示
- Qt中添加背景图片的方法
- NSButton NSImageview 添加背景图片
- 给 UINavigationBar 设置背景图片的最简单方法
- 精灵背景图片、音乐及金币的添加
- MFC中设置对话框颜色、添加背景图片、添加音乐的方法
- 关于devxepress的layoutcontrol添加背景图片
- windows——为按钮添加背景图片
- MFC对话框添加背景图片
- MFC一一添加背景图片并让控件实现透明的
- 【WPF】Button按钮添加背景图片
- 如何给对话框添加背景图片及图片按钮CBUttonST
- VS2010中 为图片添加背景图片
- QT 给界面添加背景图片