I have the following code that creates a UIView that I assign to the UITableViewCell property selectedBackgroundView . Everything works as expected, except for the background subview, which is transparent.
I use the same code to create a custom view that I assign a backgroundView , and it works fine.
What causes the transparency of the subview view for selectedBackgroundView , and how can I avoid this?
- (UIView*) makeSelectedBackgroundView { // dimensions only for relative layout CGRect containerFrame = CGRectMake(0, 0, 320, 40); UIView* containerView = [[UIView alloc] initWithFrame:containerFrame]; containerView.autoresizesSubviews = YES; // dimensions only for relative layout CGRect subframe = CGRectMake(5, 5, 310, 30); UIView* subview = [[UIView alloc] initWithFrame:subframe]; subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; subview.backgroundColor = [UIColor redColor]; subview.layer.cornerRadius = 5; subview.layer.borderWidth = 2; subview.layer.borderColor = [UIColor greenColor].CGColor; [containerView addSubview:subview]; return containerView; }
source share