user1344851
user1344851

Reputation:

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. How can I do this?

Upvotes: 1

Views: 800

Answers (3)

Carl Veazey
Carl Veazey

Reputation: 18363

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.

Upvotes: 1

Peter Zhou
Peter Zhou

Reputation: 4231

You can hide the top status bar with the following code

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

Upvotes: 0

Eiko
Eiko

Reputation: 25632

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.

Upvotes: 2

Related Questions