gpt4 book ai didi

ios - 调整 UITableViewCell 大小以适合标签或图像和圆角

转载 作者:行者123 更新时间:2023-11-30 12:36:21 25 4
gpt4 key购买 nike

我附上一个sample project让您测试并看看我能做些什么来解决这个问题。

我正在尝试动态调整图像的高度大小,同时围绕每个其他单元格的两个角。这样做会导致掩模被切断。

基本上这就是我想要实现的目标:

  1. UITableView 的行高设置为自动。

    _nTableView.rowHeight = UITableViewAutomaticDimension;
    _nTableView.estimatedRowHeight = 150;
  2. 使用 CustomTableViewCell 使用 SDWebImage 库下载图像

    [self.nImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){}];
  3. 将单元格配置为根据其行进行圆角

    UIBezierPath *maskPath = [UIBezierPath
    bezierPathWithRoundedRect:self.bubbleView.bounds
    byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerTopLeft)
    cornerRadii:CGSizeMake(20, 20)];

    CAShapeLayer *maskLayer = [CAShapeLayer layer];

    maskLayer.frame = self.bubbleView.bounds;
    maskLayer.path = maskPath.CGPath;

    self.bubbleView.layer.mask = maskLayer;

执行上述操作会导致 mask 被切断,但高度计算正确。见下文: enter image description here

基于此stack overflow's question ,如果有面具,我们需要将其取下。我尝试在 awakeFromNib 方法中将掩码设置为 nil,但这没有影响。

self.nImageView.layer.mask = nil;
self.nImageView.layer.masksToBounds = NO;

我也尝试遵循此question的答案但这会导致应用程序崩溃。

提前谢谢您。

最佳答案

这是一种可能的解决方案 - 可能不是最好的,可能不能完全满足您的需要,但可能会让您上路......

不要尝试在自定义 UITableViewCell 类中操作图层/蒙版,而是使用 UIView 子类作为图像持有者。该类的代码可以处理圆角和图层/蒙版尺寸更新。

请参阅此处的示例:https://github.com/DonMag/dhImage

关于ios - 调整 UITableViewCell 大小以适合标签或图像和圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42817383/

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