Search code examples
ios5uiviewcontrollerios6iphone-5ios4

UIview clear a zone


This is an inherited code, I would like to change as few as possible, just give support for iphone5 (taler) screen size.

Somewhere I have a code like this:

[self.view addSubview:leftSwipedViewController.view];

The problem is: the parent UIViewController has filled out the 480x2 -> 568x2 zone ( difference between iphone4 and iphone5) the new swiped UIController will fill the 0->480x2 height zone. I would like to clear the remain space with a nice white color. How to do it?

something like [self.view clearRectangle(0,568-480,320,568, color.white)]; but this function doesn't exist as is.

Is there any better, fast solution? - I don't want to create a xib file for a code where the component are place from within code to X, Y coordinates.


Solution

  • Yes, it's very simple actually

    Right before adding your view, do this:

    UIView *whiteView = [[UIView alloc] initWithFrame:self.view.bounds];
    whiteView.tag = 123; // you'll need it if you want to remove it later.
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    [self.view addSubview:leftSwipedViewController.view];
    

    When you want to remove it, do this:

    [[self.view viewWithTag:123] removeFromSuperview];
    

    However, the correct approach would be to make your leftSwipedViewController support both heights