[英]Can't seem to add a sublayer to my UITableViewCell subclass
此代码从UITableViewCell的子类中运行
CALayer* greenLayer = [CALayer layer];
greenLayer.backgroundColor = [UIColor greenColor].CGColor;
CGRect frame = CGRectMake(0, 0, 320, self.bounds.size.height);
greenLayer.frame = frame;
[self.backgroundView.layer addSublayer:greenLayer];
但是什么也没发生
与其将子层添加到backgroundView中, contentView
将其添加到单元格的contentView
:
[self.contentView.layer addSublayer:greenLayer];
或者,您可以直接设置contentView的backgroundColor
属性:
self.contentView.backgroundColor = [UIColor greenColor];
这是导致该问题的另一段代码。 我在错误地检索单元。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.