iOS7导航栏半透明=否

标签 ios objective-c uinavigationbar

我有一个背景图像,所有 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 ,然后在 文件大纲选择导航栏并在 中更改它属性检查员

Attributes Inspector Navigation Bar

关于iOS7导航栏半透明=否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21734399/

相关文章:

ios - SLComposeViewController setInitialText 未显示在 View 中

ios - UISearchController 禁用取消按钮

IOS/objective-C :Animation of Multiple CGAffineTransformations

ios - UIView 不从底部向上滑动

objective-c - 在 Cocoa 中添加一个新窗口

objective-c - 使用文本字段设置变量的值

ios - Web Socket 无法在 iOS 中使用 objective-c 打开

iphone - 使用 searchBar 时隐藏后退按钮

ios - 在 iOS 6 和 iOS 7 上为 UINavigationBar 管理自动布局

ios - 使用自动调整大小的阿拉伯语英语 iPhone 用户界面?