gpt4 book ai didi

objective-c - 在 UITableViewCell 上绘制阴影

转载 作者:可可西里 更新时间:2023-11-01 06:19:53 26 4
gpt4 key购买 nike

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

enter image description here

最佳答案

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

        //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];

关于objective-c - 在 UITableViewCell 上绘制阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9245369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com