Raj
Raj

Reputation: 1213

How can i add button or any view on the Status bar?

I want to add a button or any custom view on the status bar in the iPhone,

If apple not allow to customize the status bar than is it possible to add any button or view over the status bar...

Is there any one have idea about this please share with me.

Thanks,

Upvotes: 1

Views: 2954

Answers (3)

Senthilkumar
Senthilkumar

Reputation: 2481

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

// Create window
UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.backgroundColor=[UIColor redColor];

// Dont make the statusWindow keyWindow or the keyboard won't work!
// [statusWindow makeKeyAndVisible];

// Create statusBarButton
UIButton *statusBarButton = [UIButton buttonWithType:UIButtonTypeContactAdd];

statusBarButton.frame = CGRectMake(230, 2, 15, 15);
statusBarButton.backgroundColor=[UIColor redColor];
[statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; 

// Place button into the new window

    // Instead, add this:
[self.window makeKeyAndVisible]; // has to be main window of app
statusWindow.hidden = NO;

[statusWindow addSubview:statusBarButton];

Upvotes: 1

huqinghe
huqinghe

Reputation: 11

A good idea

UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.backgroundColor=[UIColor redColor];

Upvotes: 1

Vidya Murthy
Vidya Murthy

Reputation: 530

You could hide the default status bar and create a custom bar with the same height as the status bar and display it on the view. Apple does not allow you customize the status bar other than changing its color(gray/black), opacity(opaque/translucent) and visibility(hidden/visible).

Upvotes: 1

Related Questions