首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewCell内阴影右侧

UITableViewCell内阴影右侧
EN

Stack Overflow用户
提问于 2014-03-16 05:21:48
回答 3查看 1.4K关注 0票数 0

我试图单独在右侧为UITableViewCell创建内部阴影。我就是这么做的

代码语言:javascript
复制
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];
}

但在这里,我的问题是,每当我滚动时,阴影变得越来越暗。也超出了小区界限,破坏了小区设计。我怀疑它会被反复添加。有人能帮我解决这个问题吗?我没有兴趣使用图像作为阴影。因此,除使用图像以外的任何其他解决方案都将不胜感激。提前谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-03-18 17:11:09

我发现了问题。我应该这么做的,

代码语言:javascript
复制
self.contentView.superview.clipsToBounds = YES;
    self.contentView.clipsToBounds = YES;

现在一切都像魅力一样。

票数 1
EN

Stack Overflow用户

发布于 2014-03-18 04:36:41

确保您正在正确地使用dequeueReusableCellWithIdentifier。下面的代码对我来说很好

代码语言:javascript
复制
- (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;
}
票数 2
EN

Stack Overflow用户

发布于 2014-03-16 06:36:57

每次滚动单元格刷新和视图再次添加时,您可以做两件事

一个确保不加阴影,你不会再加它。

删除所有子视图,并在创建单元格时再次添加它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22433296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档