我需要圆形,可变高度的tableview单元格。
我使用以下代码创建四舍五入的背景:
- (void)roundView:(UIView *)view withRadius:(float)radius andColour:(UIColor *)colour
{
view.backgroundColor = [UIColor whiteColor];
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
CGMutablePathRef pathRef = CGPathCreateMutable();
CGRect bounds = CGRectInset(view.bounds, 0.0f, 0.0f);
CGPathAddRoundedRect(pathRef, nil, bounds, radius, radius);
layer.path = pathRef;
CFRelease(pathRef);
layer.fillColor = colour.CGColor;
[view.layer insertSublayer:layer atIndex:0];
}
问题在于,如果将一个较高的单元格弄圆,则在重新使用它时,较早的子层仍然存在,并且尽管新的(较小的)高度正确,但外观是盒子的底边缘没有倒圆。大概是(更大)的现有层被裁剪了。
一个明显的想法是删除子层,但是我做不到。我尝试创建一个新单元,但不重复使用它,但这似乎是不可能的。
我回想起曾经在某个按钮上完成过此操作的地方...
self.buttonCancel.layer.cornerRadius = 10;
self.buttonCancel.clipsToBounds = YES;
它也可以在这里工作...
cell.textBlurb.layer.cornerRadius = 10;
cell.textBlurb.clipsToBounds = YES;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句