0

How I can change status bar colour to custom colour on button tap? Something like when hotspot is activated.

I think I can add a subview to the current window and set the background property to the desired colour but this is a hack, I wonder if there's a better way.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mhdali
  • 690
  • 7
  • 17
  • did you check http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7 ? – Argent May 19 '14 at 06:54
  • Yes I did, but what I need is something different, I need to set a custom status bar colour on button tap. – Mhdali May 19 '14 at 07:36

2 Answers2

1

Try this code :

In your info.plist

  • Set View controller-based status bar appearance to NO
  • Set Status bar style to UIStatusBarStyleLightContent

In AppDelegate method :

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) // for ios7
{
   UIView *yourview=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
   yourview.backgroundColor=[UIColor redColor];
   [self.window.rootViewController.view addSubview:yourview];
}

I think this will helps you. :)

Soumya Ranjan
  • 4,817
  • 2
  • 26
  • 51
  • This is what I expected, but like I said this is a hack, I'm searching for a better way. Thanks – Mhdali May 19 '14 at 07:43
  • Don't use the `[[UIDevice currentDevice] systemVersion]` to detect the system version, but use the foundation numer, as per [Apple example](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/SupportingEarlieriOS.html#//apple_ref/doc/uid/TP40013174-CH14-SW1): `if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)` – rckoenes May 19 '14 at 07:47
0

Use This code .

UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor redColor];
[self.window.rootViewController.view addSubview:view];

Hope this code is useful for you.

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
  • This is what I expected, but like I said this is a hack, I'm searching for a better way. – Mhdali May 19 '14 at 07:42
  • 2
    It's not a hack, it is you only option. In iOS 7 the statusbar is transparent an by placing a view behind it you can give it a color. – rckoenes May 19 '14 at 07:52