Draw shadow on top of UITableViewCell

后端 未结 1 991
灰色年华
灰色年华 2021-02-06 17:35

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

\"en

相关标签:
1条回答
  • 2021-02-06 18:30

    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];
    
    0 讨论(0)
提交回复
热议问题