xcode 如何更改导航栏背景
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10718874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I change navigationBar Background
提问by Civan Kazanova
I try change to background of navigationBar.
我尝试更改为导航栏的背景。
Search.h:
搜索.h:
#import <UIKit/UIKit.h>
@interface Search : UIViewController
@end
Search.m:
搜索.m:
#import "Search.h"
@implementation Search
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image = [UIImage imageNamed:@"navigation_header.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
I can't change navigation background.
我无法更改导航背景。
Thanks.
谢谢。
回答by Mick MacCallum
This is actually simpler to do then you think. In your app delegate...
这实际上比你想象的更简单。在您的应用程序委托中...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar.png"] forBarMetrics:UIBarMetricsDefault];
return YES;
}
This will universally change your navigation bar background image.
这将普遍改变您的导航栏背景图像。
Note:I believe UINavigationBar's
"appearance" property is available in iOS 5 and up.
注意:我相信UINavigationBar's
“外观”属性在 iOS 5 及更高版本中可用。
回答by Rinju Jain
viewController.h
视图控制器.h
IBOutlet UINavigationBar *navBar;
viewController.m //for color
viewController.m //用于颜色
- (void)viewDidLoad{
[super viewDidLoad];
[navBar setTintColor:[UIColor colorWithRed:0.0/255.0 green:100.0/255.0 blue:20.0/255.0 alpha:1.0]];
}
//for image
//对于图像
UIImage *image = [UIImage imageNamed:@"navigation_header.png"];
[self.navigationController.navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
回答by Prasad G
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[Search alloc] initWithNibName:@"Search" bundle:nil] autorelease];
navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:[navControl view]];
[self.window makeKeyAndVisible];
}
}
Write this method in AppDelegate.m. I think it will be helpful to you.
在 AppDelegate.m 中编写此方法。我想它会对你有所帮助。