2013-10-26 191 views
0

我正在學習objective-c,並且在頂部導航欄變黑時遇到了一些麻煩。這是我到目前爲止:更改屏幕導航欄爲黑色

// AppDelegate.h 
#import <UIKit/UIKit.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 
@property (strong, nonatomic) UINavigationController *navigationController; 
@end 

// AppDelegate.m 
#import "AppDelegate.h" 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; // optional 
    return YES; 
} 

我在做什麼錯在這裏/不理解這個?這將如何解決?是因爲我沒有合成navigationController嗎? (你什麼時候需要綜合的東西嗎?)

回答

0

這應該在viewWillAppear中完成或didappear

默認情況下,在iOS應用程序的UINavigationBar的是藍色的。蘋果有一些內置的樣式,你可以使用

[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque]; 

提供的選項包括:

UIBarStyleBlack 
UIBarStyleBlackOpaque 
UIBarStyleBlackTranslucent 
UIBarStyleDefault 

UIBarStyleBlackOpaque和UIBarStyleTranslucent已經貶值。如果需要,您應該使用UIBarStyleBlack並將屬性「半透明」設置爲「是」

您還可以使用以下兩行代碼之一將顏色更改爲您希望的任何顏色並調整顏色值。

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.7 green:.5 blue:.2 alpha:1]; 


self.navigationController.navigationBar.tintColor = [UIColor blackColor]; 
0

試圖通過設置Tint

[navbar setTint color:[uicolor blackColor]]; 

navigationController.navigationBar.barTintColor =的UIColor綠彩]。

0

如果您試圖使用導航控制器堆棧創建應用程序,它通常看起來像這樣。

//Appdelegate.h 
#import <UIKit/UIKit.h> 
@interface AppDelegate : UIResponder <UIApplicationDelegate> 
@property (strong, nonatomic) UIWindow *window; 
@end 

//Appdelegate.m 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    MyCustomViewController *vc = [[MyCustomViewController alloc] init]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc]; 
    navigationController.navigationBar.barStyle = UIBarStyleBlack; 
    self.window.rootViewController = navigationController; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 
+0

並將在頭文件會是什麼樣呢? – David542

0

使用,這可能是幫助

self.navigationController.navigationBar.tintColor = [UIColor blackColor];