gpt4 book ai didi

ios - 如何在 UITableViewCell 中实现带圆角的投影?

转载 作者:行者123 更新时间:2023-11-29 00:50:13 25 4
gpt4 key购买 nike

我想在UITableViewCell中实现投影和圆角

- (void)tableView:(UITableView *)tableView willDisplayCell:(MembershipCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

cell.contentView.backgroundColor = [UIColor clearColor];
CGRect rect = cell.frame;
UIView *whiteRoundedCornerView = [[UIView alloc] initWithFrame:CGRectMake(8,8,rect.size.width-8,rect.size.height)];
whiteRoundedCornerView.backgroundColor = [UIColor whiteColor];
whiteRoundedCornerView.layer.masksToBounds = NO;
whiteRoundedCornerView.layer.cornerRadius = 3.0;
whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(0,0);
whiteRoundedCornerView.layer.shadowOpacity = 0.75;
[cell.contentView addSubview:whiteRoundedCornerView];
[cell.contentView sendSubviewToBack:whiteRoundedCornerView];
}

我正在使用上面的代码,但它在单元格的顶部和左侧显示阴影。

最佳答案

那是因为你在右边和底部没有空间,你需要在右边和底部有一些空间来显示阴影。此外,您可以将 shadowRadius 添加到层中以控制阴影的半径。尝试以下

- (void)tableView:(UITableView *)tableView willDisplayCell:(MembershipCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

cell.contentView.backgroundColor = [UIColor clearColor];
CGRect rect = cell.frame;

UIView *whiteRoundedCornerView;

if (![cell.contentView viewWithTag:SOME_TAG_VALUE]) {

whiteRoundedCornerView = [[UIView alloc] initWithFrame:CGRectMake(8,8,rect.size.width-16,rect.size.height-16)];
whiteRoundedCornerView.backgroundColor = [UIColor whiteColor];
whiteRoundedCornerView.layer.masksToBounds = NO;
whiteRoundedCornerView.layer.cornerRadius = 3.0;
whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(0,0);
whiteRoundedCornerView.layer.shadowOpacity = 0.75;
whiteRoundedCornerView.layer.shadowRadius = 1.0;
whiteRoundedCornerView.tag = SOME_TAG_VALUE;
[cell.contentView addSubview:whiteRoundedCornerView];
}

[cell.contentView sendSubviewToBack:whiteRoundedCornerView];
}

关于ios - 如何在 UITableViewCell 中实现带圆角的投影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38202523/

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