如何在IOS5中自定义UINavigationBar
在IOS5中,我还不知道如何自定义UINavigationBar。
我的代码是这样的:
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithWhite:0.5f alpha:1.0]]; [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor],UITextAttributeTextColor ,[UIColor blackColor], UITextAttributeTextShadowColor ,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset ,[UIFont fontWithName:@"Arial" size:20.0],UITextAttributeFont , nil]]; // Customize UIBarButtonItems UIImage *gradientImage44 = [[UIImage imageNamed: @"title__bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault]; [[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor ,[UIColor whiteColor], UITextAttributeTextShadowColor ,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset ,[UIFont fontWithName:@"Arial" size:14.0],UITextAttributeFont , nil] forState:UIControlStateNormal]; // Customize back button items differently UIImage *buttonBack30 = [[UIImage imageNamed:@"bn_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
这张图是在PopoverView中使用的UINavigationViewController。
这张图是由Modal打开的UINavigationViewController。
正如你所看到的,我设置了背景图像,不过NavigationBar的边框是不同的。
这是关于PopoverView的问题吗?
我不知道我错过了什么。
请告诉我你的build议。 谢谢!!! 新年快乐!!!
转到AppDelegate.m并粘贴下面的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
将状态栏设置为黑色。
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
将@“menubar.png”更改为图像的文件名。
UIImage *navBar = [UIImage imageNamed:@"menubar.png"]; [[UINavigationBar appearance] setBackgroundImage:navBar forBarMetrics:UIBarMetricsDefault];
看看这个: UINavigationBar苹果开发者参考