问题
I have a background image, the same image in all views, but the nav bar traslucent is set by default to YES and the background is not homogeneous. I tried various solutions but nothing change :(
my AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
my AppDelegate.m
#import "AppDelegate.h"
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >>16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[UINavigationBar appearance] setBarTintColor: UIColorFromRGB(0x45312a)];
[[UINavigationBar appearance] setTintColor: [UIColor whiteColor]];
NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[ver objectAtIndex:0] intValue] >= 7) {
self.navigationController.navigationBar.translucent = NO;
}
return YES;
}
but in the line:
self.navigationController.navigationBar.translucent = NO;
give me these error: Property 'navigationController' not found on object of type 'AppDelegate *'
Anyone can help me? Thanks!
回答1:
You can do that in your root view controller
//inside the root view controller
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
}
Also you can toggle translucent in the interface builder. Select your Navigation Controller then in the Document Outline select the Navigation Bar and just change it in the Attributes Inspector
回答2:
Because the AppDelegate is not a UINavigation Controller. You can do what you done on previous lines is to set the navigationbar appearance globally.
[[UINavigationBar appearance] setTranslucent:NO];
回答3:
try this for ios 7
[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
来源:https://stackoverflow.com/questions/21734399/ios7-nav-bar-translucent-no