4

When an iOS app rotates it will reveal a black background when the app is between portrait and landscape. Is it possible to change this color from the default black to white? Changing the UIWindow's background color will not help. Here is an example of the black background in Safari during rotation: Safari rotation

Jorn
  • 1,054
  • 9
  • 25
  • Are you trying to change the color of Safari, or your app? – Logan Mar 15 '14 at 17:20
  • My app, Safari was just an example. Sorry for the confusion. – Jorn Mar 15 '14 at 20:00
  • I would really like to know what is Apple's stance towards apps that change this default behaviour (i.e., if it will get your app rejected from the AppStore, if they think whatever hack you use to fix it might break in a future release of the OS, etc.) – Nicolas Miari Aug 20 '15 at 02:36
  • I have not found anything in the App Store Review Guidelines that suggest that an app doing this could be rejected; however, keep in mind that iOS 9 brings new features that did not exist when the question was asked. More specific, the split screen multitasking means that you will not be able to change the background of the whole screen. – Jorn Aug 23 '15 at 17:16

4 Answers4

6

I have done something similar but I couldn't find the source now, but here is the idea:

Create and add a significantly larger view as backing view and center it.

Add the UIWebView as subview of this large view whose background is white.

Re-position the center of the UIWebView, too.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • 1
    Brilliant. I'm deleting my answer and up voting yours! What a great trick. – matt Mar 15 '14 at 17:54
  • 1
    Thanks! I was hoping Apple provided a way to set the color, but this solution is very simple and quite clean. Just need to find the perfect size for the view now :) – Jorn Mar 15 '14 at 20:09
4

You can do this way: enter image description here

Add a UIViewController and set it as initial VC (in screenshot it is MainVC).
Add two UIViewContainer: first for holding your background view , and second for your other vcs.
Override viewDidLayoutSubviews in implementation file of background VC (in this case the .m file of red VC)

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    //Some hardcode :)
    self.view.frame = CGRectMake(-100, -100, 1136, 1136);
}

After doing this you will have something like this:

enter image description here

I know this is not the best solution, but you can do this way until you find the best one.

arturdev
  • 10,884
  • 2
  • 39
  • 67
1

I got the same issue. As I understand that you want to remove the black background. The easiest solution that I used is set you window clipsToBounds = true instead of your rootViewController.

window?.clipsToBounds = true
Long.h.nguyen
  • 21
  • 1
  • 1
0

You can solve the problem by adding empty general view controller with oversized bounds into your root viewController and make it the lowest in the view hierarchy:

CGFloat length = 2*MAX(rootViewController.view.bounds.size.height, rootViewController.view.bounds.size.width);

UIView *oversizedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, length, length)];
oversizedBackgroundView.center = vc.view.center;
oversizedBackgroundView.backgroundColor = [UIColor whiteColor];
rootViewController.view.clipsToBounds = NO;
[rootViewController.view addSubview:oversizedBackgroundView];
[rootViewController.view sendSubviewToBack:oversizedBackgroundView];

self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];

The key point here is to set clipsToBounds to NO

malex
  • 9,874
  • 3
  • 56
  • 77