gpt4 book ai didi

ios - 状态栏背景颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:36 24 4
gpt4 key购买 nike

我正在使用 ios 7 我想设置状态栏背景图像。我已经这样做了,但它仍然没有改变任何东西:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor redColor]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}

最佳答案

我已经像 .h 文件那样做了

@property (retain, nonatomic) UIWindow *statusBarBackground;

在.m文件中

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.statusBarBackground = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)];
self.statusBarBackground.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"statusbar_bg"]];
[self.statusBarBackground makeKeyAndVisible];
}

将此添加到您的 Controller

- (void) viewDidLayoutSubviews {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
CGRect viewBounds = self.view.bounds;
if (viewBounds.origin.y == 0) {
CGFloat topBarOffset = self.topLayoutGuide.length;
viewBounds.origin.y -= topBarOffset;
self.view.bounds = viewBounds;
}
}
}

关于ios - 状态栏背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20760511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com