1

I need to remove the battery and watch icons from the status bar in an iPad application. How can I do this?

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81

3 Answers3

2

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.

Eiko
  • 25,601
  • 15
  • 56
  • 71
1

You can use a UIWindow subclass that is laid out as an opaque view copying the status bar appearance. 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. 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:

@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.

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
0

You can hide the top status bar with the following code

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
Peter Zhou
  • 3,881
  • 2
  • 21
  • 19