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 = CGRectM开发者_StackOverflow社区ake(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];
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;
}
精彩评论