1

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,

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Raj
  • 1,213
  • 2
  • 16
  • 34

3 Answers3

1

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

Vidya Murthy
  • 530
  • 1
  • 8
  • 22
  • okay its fine but is it possible to add any event on status bur ? – Raj Feb 15 '12 at 05:39
  • When you customize a view, you can add any type of touch/click events to it. You will just be replicating the view as status bar, not modifying the status bar itself. – Vidya Murthy Feb 15 '12 at 05:52
  • I don't want to hide the status bar i just want to add another transparent view over the status bar .. – Raj Feb 15 '12 at 05:54
  • Then as @Maulik suggested, you could look at [this](http://stackoverflow.com/questions/2833724/adding-view-on-statusbar-in-iphone) – Vidya Murthy Feb 15 '12 at 06:00
1
[[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];
phi
  • 10,634
  • 6
  • 53
  • 88
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
1

A good idea

UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.backgroundColor=[UIColor redColor];
phi
  • 10,634
  • 6
  • 53
  • 88
huqinghe
  • 11
  • 2