Search code examples
iosbackgroundaddsubview

Subview shows up with grey background color when added


I have a tableview to the left (it's an iPad application) and a empty subview to the right, that is filled when the user touches a cell. This is how my didSelect... looks like:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SecondViewController *remedyScreen = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];       
    [self.rightPanel addSubview:remedyScreen.view];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

My problem is that this SecondViewController always shows up with a grey background and it's set to clearClear on the xib and also Opaque property is unchecked. I assume this strange grey background color is coming from the subview just created because even if I put a color to the self.rightPanel it is covered by the grey color when I add the subview to it. I've done the setup in the code setting clearColor and Opaque = NO but I get the same grey background. I am missing something there?


Solution

  • Try this:

    UIView *backView = [[[UIView alloc] CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    backView.backgroundColor = [UIColor clearColor];
    self.view.backgroundView = backView;