有人可以解释一下如何仅在最后一个单元格上创建一个或两个像素的阴影(换句话说,我不希望整个表格视图周围有阴影,仅是底部单元格。我的图像谈论:

最佳答案

解决了。使用以下代码在UITableViewCell的底部产生一个非常漂亮的细微阴影。使其看起来略微超出页面:)

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(3, 49, cell.frame.size.width-26, 3)];/// change size as you need.
        separatorLineView.backgroundColor = shadowColor;// you can also put image here
        UIBezierPath *roundedShadow = [UIBezierPath bezierPathWithRoundedRect:separatorLineView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8.0f, 8.0f)];
        CAShapeLayer *newSeparatorShape = [[CAShapeLayer alloc] init];
         [newSeparatorShape setPath:roundedShadow.CGPath];

        separatorLineView.layer.mask = newSeparatorShape;

        [cell.contentView addSubview:separatorLineView];


另外,不要忘记将其放在.m文件的顶部#import <QuartzCore/QuartzCore.h>

09-25 22:06