如何让CALayer可调整大小?当我将子层插入tableViewCell,然后更改单元格高度时,如何使其适合单元格的新大小?
CALayer *innerShadowLayer = [CALayer layer];
innerShadowLayer.contents = (id)[UIImage imageNamed: @"innershadow"].CGImage;
innerShadowLayer.contentsCenter = CGRectMake(10.0f/21.0f, 10.0f/21.0f, 1.0f/21.0f, 1.0f/21.0f);
innerShadowLayer.frame = cell.frame;
[cell.backView.layer insertSublayer:innerShadowLayer atIndex:0];
答案 0 :(得分:2)
我不确定您放置此代码的位置,但如果它位于UITableViewCell子类中,则可以将其保存为实例变量并添加此代码
- (void)layoutSubviews{
[super layoutSubviews];
innerShadowLayer.frame = cell.frame;
}