How to customize UINavigationBar in IOS5

六眼飞鱼酱① 提交于 2019-12-11 07:50:03

问题


In IOS5, I do not yet know how to customize UINavigationBar.

My code is like this:

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

This pic is UINavigationViewController used in PopoverView.

This pic is UINavigationViewController opened by Modal.

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

Is this a problem about PopoverView?

I do not know What I'd missed.

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


回答1:


Goto AppDelegate.m and paste the code under

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

Set the status bar to black color.

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

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

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

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



回答2:


Have a look at this: UINavigationBar Apple developer reference



来源:https://stackoverflow.com/questions/8736171/how-to-customize-uinavigationbar-in-ios5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!