cocoa-touch - 为 UITableView 创建阴影

标签 cocoa-touch uitableview core-graphics

有人能解释一下如何只在最后一个单元格上创建一个或两个像素的投影吗(换句话说,我不希望整个表格 View 周围有阴影,只是底部单元格。什么的图像我在说:

enter image description here

最佳答案

已解决。使用以下代码在您的 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>

关于cocoa-touch - 为 UITableView 创建阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17758164/

相关文章:

objective-c - unsafe_retained 属性

ios - 修复了 iOS 11 中 UITableViewCell 中 UIImageView 的大小

ios - 创建自定义 UITableView 索引 iOS

objective-c - iOS:在 ImageView 上绘制矩形并调整边框

iphone - 如何更改 CGContextRef 的大小

iphone - UIWebView 支持的文件格式

objective-c - 对 cocoa 中的对象 NSMutableArray 进行排序会给出 SIGABRT

iphone - 自动释放iPhone

ios - 带有解析查询的 UITableView 未加载

ios - 如何在路径中制作透明区域uiimage