RAGOpoR
RAGOpoR

Reputation: 8168

How to make CALayer resizeable?

How can I make CALayer resizable? When I insertSublayer into tableViewCell, then change the cell height, how can I make it fit to the new size of the cell?

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];

Upvotes: 1

Views: 380

Answers (1)

Patrick Hernandez
Patrick Hernandez

Reputation: 585

I am not sure where you are placing this code, but if it's in the UITableViewCell subclass then you can save it as an instance variable and add this code

- (void)layoutSubviews{
    [super layoutSubviews];
    innerShadowLayer.frame = cell.frame;
}

Upvotes: 2

Related Questions