0

我已经创建了一个XIB没有使用Status Barfor的应用程序iOS7,现在我需要Status bar在我的应用程序上添加并且Status bar background color应该与Navigation bar背景颜色相同。所以我尝试过(在我的info.plist):

1) Set View controller-based status bar appearance to NO
2) Set Status bar style to UIStatusBarStyleLightContent 

这是我的代码App Delegate

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];

所以我得到如下图所示的输出:

在此处输入图像描述

我也得到了我在屏幕下方给出的 UIButtons 的错位(它隐藏了 20 个像素)。

你能帮我解决这个问题吗?我需要如下图所示的输出:

在此处输入图像描述

任何帮助将不胜感激,谢谢。

第三屏:

在此处输入图像描述

4

3 回答 3

1

请在 AppDelegate.h(或)constants.h 中定义它

  #define isIOS7  ([[[UIDevice currentDevice]systemVersion]floatValue] >=7.0)?YES:NO

在 viewDidLoad 下写下这几行。

  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
   UIView *addStatusBar = [[UIView alloc] init];
   addStatusBar.frame = CGRectMake(0, 0, 320, 20);
    addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1];


     //change this to match your navigation bar
    [self.window.rootViewController.view addSubview:addStatusBar];
  }

或者我们可以在 xib 中手动更改它。

通过将每个元素向下移动 20px。

见这张图片

于 2014-09-09T11:31:13.040 回答
1

在 viewDidLoad 方法中添加以下代码:

float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];

if (systemVersion >= 7.0) 
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
于 2014-06-30T07:15:40.607 回答
0

对很少有人提出这个建议感到惊讶。这是正确的方法(没有黑客)

首先,让您的导航栏的 Y 原点为 20。

然后在 .h 文件中,将您的 ViewController 设置为 UIBarPositioningDelegate:

@interface XYZViewController : UIViewController <UIBarPositioningDelegate>

在 .m 文件中:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.delegate = self;
}

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { 
    return UIBarPositionTopAttached; 
}
于 2014-07-26T06:25:51.267 回答