1

我尝试更改导航栏的背景。

搜索.h:

#import <UIKit/UIKit.h>

@interface Search : UIViewController

@end

搜索.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];

}

我无法更改导航背景。

谢谢。

4

3 回答 3

4

这实际上比你想象的要简单。在您的应用委托中...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar.png"] forBarMetrics:UIBarMetricsDefault];
    return YES;
}

这将普遍改变您的导航栏背景图像。

注意:我相信UINavigationBar's“外观”属性在 iOS 5 及更高版本中可用。

于 2012-05-23T16:26:23.523 回答
2

视图控制器.h

IBOutlet UINavigationBar *navBar;

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]];
}

//对于图像

 UIImage *image = [UIImage imageNamed:@"navigation_header.png"];
[self.navigationController.navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
于 2012-05-23T11:33:14.967 回答
0
- (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];

}

在 AppDelegate.m 中编写此方法。我想这会对你有所帮助。

于 2012-05-23T11:45:40.777 回答