我有以下代码创建一个UIView我分配给我UITableViewCell的selectedBackgroundView属性的代码.一切都按预期工作,但子视图的背景除外,它是透明的.
我使用相同的代码来创建我分配的自定义视图backgroundView,并且工作正常.
是什么导致该子视图透明selectedBackgroundView,我该如何避免?
- (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 …Run Code Online (Sandbox Code Playgroud)