我有一个背景图像,所有 View 中的图像都相同,但导航栏 traslucent 默认设置为 YES 并且背景不均匀。我尝试了各种解决方案,但没有任何改变:(
我的 AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
我的 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;
}
但在这一行:
self.navigationController.navigationBar.translucent = NO;
给我这些错误:在“AppDelegate *”类型的对象上找不到属性“navigationController”
任何人都可以帮助我吗?谢谢!
最佳答案
您可以在 Root View Controller 中执行此操作
//inside the root view controller
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
}
您也可以在界面生成器中切换半透明。选择您的导航 Controller ,然后在 文件大纲选择导航栏并在 中更改它属性检查员
关于iOS7导航栏半透明=否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21734399/