如何在IOS5中自定义UINavigationBar

如何在IOS5中自定义UINavigationBar

本文介绍了如何在IOS5中自定义UINavigationBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IOS5中,我还不知道如何自定义UINavigationBar。

In IOS5, I do not yet know how to customize 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。

This pic is UINavigationViewController used in PopoverView.

这个pic是由Modal打开的UINavigationViewController。

This pic is UINavigationViewController opened by Modal.

As你看,我设置了背景图像,但是NavigationBar的边框不同。

As you see, I set background-image, nevertheless NavigationBar's border is different.

这是关于PopoverView的问题吗?

Is this a problem about PopoverView?

我不知道我错过了什么。

I do not know What I'd missed.

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

Please tell me your advice. Thanks!!! and Happy new year!!!

推荐答案

转到AppDelegate.m并粘贴代码

Goto AppDelegate.m and paste the code under

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

将状态栏设置为黑色。

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque
                                            animated:NO];

将@menubar.png更改为图片的文件名。

Change @"menubar.png" to the file name of your image.

 UIImage *navBar = [UIImage imageNamed:@"menubar.png"];

[[UINavigationBar appearance] setBackgroundImage:navBar
                                   forBarMetrics:UIBarMetricsDefault];

这篇关于如何在IOS5中自定义UINavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 10:53