开发者

How to make CALayer resizeable?

开发者 https://www.devze.com 2023-03-17 17:48 出处:网络
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?

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号