2012-01-05 97 views
1

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

此圖是由Modal打開的UINavigationViewController。 enter image description here

如您所見,我設置了背景圖像,但NavigationBar的邊框不同。

這是關於PopoverView的問題嗎?

我不知道我錯過了什麼。

請告訴我你的建議。謝謝!!!新年快樂!!!

+0

http://stackoverflow.com/questions/5575821/custom-nav-bar-styling-ios/6389991#6389991 – 2012-04-17 15:55:32

回答

1

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