繁体   English   中英

似乎无法向我的UITableViewCell子类添加子层

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM