加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 在UITableViewCell上绘制阴影

发布时间:2020-12-16 10:30:53 所属栏目:百科 来源:网络整理
导读:如何在UITableViewCell的顶部绘制阴影? Tweetbot这样做,这是一个截图: 解决方法 您可以使用CAGradientLayer.在cellForRowAtIndexPath中,创建单元格时,创建渐变图层并将其添加到单元格中.注意,您必须导入QuartzCore框架.像这样, //top shadow UIView *topSh
如何在UITableViewCell的顶部绘制阴影? Tweetbot这样做,这是一个截图:

解决方法

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

//top shadow
        UIView *topShadowView = [[UIView alloc] initWithFrame:CGRectMake(0,self.tableView.bounds.size.width,10)];
        CAGradientLayer *topShadow = [CAGradientLayer layer];
        topShadow.frame = CGRectMake(0,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];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读