我试图单独在右侧为UITableViewCell创建内部阴影。我就是这么做的
if (![cell viewWithTag:100]) {
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(DEVICE_WIDTH, 0, 10, height)];
shadowView.layer.shadowColor = [UIColor darkGrayColor].CGColor;
shadowView.layer.shadowRadius = 5.0;
shadowView.layer.shadowOffset = CGSizeMake(-2, 0);
shadowView.layer.shadowOpacity = 0.8;
shadowView.backgroundColor = [UIColor darkGrayColor];
shadowView.tag = 100;
shadowView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[cell addSubview:self.shadowView];
}但在这里,我的问题是,每当我滚动时,阴影变得越来越暗。也超出了小区界限,破坏了小区设计。我怀疑它会被反复添加。有人能帮我解决这个问题吗?我没有兴趣使用图像作为阴影。因此,除使用图像以外的任何其他解决方案都将不胜感激。提前谢谢。
发布于 2014-03-18 17:11:09
我发现了问题。我应该这么做的,
self.contentView.superview.clipsToBounds = YES;
self.contentView.clipsToBounds = YES;现在一切都像魅力一样。
发布于 2014-03-18 04:36:41
确保您正在正确地使用dequeueReusableCellWithIdentifier。下面的代码对我来说很好
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSLog(@"new cell");
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 10, 44)];
shadowView.layer.shadowColor = [UIColor darkGrayColor].CGColor;
shadowView.layer.shadowRadius = 5.0;
shadowView.layer.shadowOffset = CGSizeMake(-2, 0);
shadowView.layer.shadowOpacity = 0.8;
shadowView.backgroundColor = [UIColor darkGrayColor];
shadowView.tag = 100;
shadowView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[cell addSubview:shadowView];
}
else
{
NSLog(@"old cell");
}
return cell;
}发布于 2014-03-16 06:36:57
每次滚动单元格刷新和视图再次添加时,您可以做两件事
一个确保不加阴影,你不会再加它。
或
删除所有子视图,并在创建单元格时再次添加它们。
https://stackoverflow.com/questions/22433296
复制相似问题