在UITableViewCell的顶部绘制阴影 [英] Draw shadow on top of UITableViewCell

查看:444
本文介绍了在UITableViewCell的顶部绘制阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 UITableViewCell 的顶部绘制阴影? Tweetbot执行此操作,屏幕截图如下:

How can I draw a shadow on the top of a UITableViewCell? Tweetbot does this, here's a screenshot:

推荐答案

您可以使用CAGradientLayer。在cellForRowAtIndexPath中,创建一个单元格时,创建一个渐变层并将其添加到您的单元格。注意,你必须导入QuartzCore框架。像这样,

You could use a CAGradientLayer. In your cellForRowAtIndexPath, when creating a cell, create a gradient layer and add it to your cell. Note, you'll have to import the QuartzCore framework. Like so,

        //top shadow
        UIView *topShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 10)];
        CAGradientLayer *topShadow = [CAGradientLayer layer];
        topShadow.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 10);
        topShadow.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.0 alpha:0.25f] CGColor], (id)[[UIColor clearColor] CGColor], nil];
        [topShadowView.layer insertSublayer:topShadow atIndex:0];

        [cell.contentView addSubview:topShadowView];

这篇关于在UITableViewCell的顶部绘制阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆