ios - IOS5自定义UINavigationBar的方法

标签 ios ios5 uinavigationbar customization

在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。 enter image description here

这张图是Modal打开的UINavigationViewController。 enter image description here

如您所见,我设置了背景图像,但是 NavigationBar 的边框不同。

这是 PopoverView 的问题吗?

我不知道我错过了什么。

请告诉我您的建议。谢谢!!!新年快乐!!!

最佳答案

转到 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];

关于ios - IOS5自定义UINavigationBar的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8736171/

相关文章:

ios - JSON 和 Alamofire 请求的问题

ios - XCode 6 项目在 ios 7.1 上 segue 后崩溃

ios - 如何在没有 IB 的情况下控制对象的自动调整大小?

iphone - 使用 NSMutableArray 将 NSDictionary 保存为 NSUserDefaults 的值

objective-c - 您如何在 Interface Builder Storyboard中跨场景连接 IBOutlets?

ios - 使用 CAAnimation 无限旋转两个变量

ios - Firebase 分页 -Swift 和 iOS。应该什么时候使用?

objective-c - 如何更改 UINavigationBar 标题标签大小?

ios - 使用向下平移关闭 UINavigationController 相对于顶部安全区域调整 UINavigationBar 的大小

swift - 导航栏中的栏按钮项不可见 - Swift