我有下面的代碼,創建一個UIView
,我分配給我的UITableViewCell
的selectedBackgroundView
屬性。一切都按預期工作,子視圖的背景是透明的。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 containerView;
}
你可以添加一張你得到的圖片和一張你期望的圖片嗎? – alinoz
你試過玩阿爾法?子視圖的[subview setAlpha:0.0]。 – alinoz