简体   繁体   English

从iPad状态栏中取出电池和手表图标

[英]Removing battery and watch icon from iPad status bar

I need to remove the battery and watch icons from the status bar in an iPad application. 我需要从iPad应用程序的状态栏中取出电池并观看图标。 How can I do this? 我怎样才能做到这一点?

No, you can't do this. 不,你不能这样做。 You can only remove the complete status bar. 您只能删除完整的状态栏。

I don't know why one would want to remove clock and battery but leave the bar, anyway. 我不知道为什么人们想要移除时钟和电池,但无论如何都要离开吧台。

You can use a UIWindow subclass that is laid out as an opaque view copying the status bar appearance. 您可以使用UIWindow子类,该子类被布置为复制状态栏外观的不透明视图。 You can set its frame accordingly so that it only blocks off the portions of the status bar that you need to hide. 您可以相应地设置其框架,以便它仅阻止您需要隐藏的状态栏部分。 Then you set the windowLevel property to something like UIWindowLevelStatusBar + 1.0f . 然后将windowLevel属性设置为UIWindowLevelStatusBar + 1.0f Hope this helps! 希望这可以帮助!

EDIT 编辑

I came up with some basic sample code. 我想出了一些基本的示例代码。 This should only be considered a proof of concept. 这应该只被视为概念证明。 There are many considerations in an attempt worthy of production code, such as rotation, different status bar styles (I'd say translucent would be impossible to do actually), and different layouts of the items in the status bar. 尝试值得生产代码有许多考虑因素,例如旋转,不同的状态栏样式(我说半透明实际上是不可能的),以及状态栏中项目的不同布局。

The UIWindow subclass: UIWindow子类:

@interface StatusBarMask : UIWindow

@end

@implementation StatusBarMask

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.windowLevel = UIWindowLevelStatusBar + 1.0f;
        self.backgroundColor = [UIColor greenColor];
        self.hidden = NO;
    }
    return self;
}

@end

And a view controller that instantiates it: 以及实例化它的视图控制器:

@interface ViewController ()

@property (nonatomic, strong) StatusBarMask *mask;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect appStatusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
    appStatusBarFrame.size.width = 384.0f;
    appStatusBarFrame.origin.x = 384.0f;
    self.mask = [[StatusBarMask alloc] initWithFrame:appStatusBarFrame];
}

@end

This will mask off the right side of the status bar with a bright green rectangle. 这将使用亮绿色矩形遮盖状态栏的右侧。 Adjust colors and sizes as needed, and consider all the gradients, curved edges, and so forth. 根据需要调整颜色和大小,并考虑所有渐变,弯曲边缘等。 With careful consideration of the various edge cases, you should be able to accomplish your goal. 仔细考虑各种边缘情况,您应该能够实现目标。

您可以使用以下代码隐藏顶部状态栏

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM