簡體   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