我正在使用 CALayer 使我的 uitableviewcells 看起来更好看。我正在尝试以这种方式执行此操作:
CALayer *btnLayer = [cell layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:10.0f];
[btnLayer setBorderWidth:5.0f];
[btnLayer setBorderColor:[[UIColor blackColor] CGColor]];
CAGradientLayer *shineLayer = [CAGradientLayer layer];
shineLayer.frame = btnLayer.bounds;
shineLayer.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithWhite:1.0f alpha:0.4f].CGColor,
(id)[UIColor colorWithWhite:1.0f alpha:0.2f].CGColor,
(id)[UIColor colorWithWhite:0.75f alpha:0.2f].CGColor,
(id)[UIColor colorWithWhite:0.4f alpha:0.2f].CGColor,
(id)[UIColor colorWithWhite:0.3f alpha:0.4f].CGColor,
nil];
shineLayer.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:0.5f],
[NSNumber numberWithFloat:0.5f],
[NSNumber numberWithFloat:0.8f],
[NSNumber numberWithFloat:1.0f],
nil];
[btnLayer addSublayer:shineLayer];
我在 tableViewController 的 cellForRowAtIndexPath 方法中执行此操作。一切都很完美,单元格发光很好,但是当我自上而下拖动单元格几次时,顶部和底部单元格再次重绘。之后细胞变得更轻。
我使用动态单元格并从数组加载数据。给我一个建议,如何正确地做到这一点。
谢谢