rajesh sukumaran rajesh sukumaran - 1 year ago 61
Swift Question

Changing only the body colour of UITableView or changing only the status bar colour

I wanted to get a specific colour to the iOS status bar ,I understand it will take the colour of the top view controllers view .
And hence I can get this by applying the colour I want for the status bar to the table view ,which would look like this

enter image description here

But when it doesn't have any rows then whole table view gets that color (Obvious! but thats not what i want)

enter image description here

Is there any way to give colour only to the top part of the tableview so that status bar gets that colour or can i change the status bar color alone .
I have

View controller-based status bar appearance

in Info.plist as NO .

Answer Source

You can apply background color to status bar like following

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
    statusBar.backgroundColor = [UIColor redColor];

Using the above code in AppDelegate didFinishLaunchingWithOptions method would change the status bar background color of entire app. If you want to change the background color to specific view controllers, then you should follow the @Lion's approach.

Hope this helps.