gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:19:42 25 4
gpt4 key购买 nike

此代码在 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];

但什么也没发生

最佳答案

不是将子层添加到背景 View ,而是将其添加到单元格的 contentView:

[self.contentView.layer addSublayer:greenLayer];

或者,您可以直接设置 contentView 的 backgroundColor 属性:

self.contentView.backgroundColor = [UIColor greenColor];

关于ios - 似乎无法向我的 UITableViewCell 子类添加子层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9966704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com