gpt4 book ai didi

ios - 为什么在 UITableViewCell 中修改此 CALayer 会导致讨厌的图形故障?

转载 作者:行者123 更新时间:2023-11-29 01:27:35 25 4
gpt4 key购买 nike

在我的cellForRowAtIndexPath方法中,我设置了图像上layercornerRadius:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("feedCell")!

if self.pictunes?.count > 0 {
// There are some pictunes to show; Create and update the posts
if self.pictuneImages.count > indexPath.row {

// We have an image for the user who made the current pictune
if let pictunerImageView = cell.contentView.viewWithTag(2) as? UIImageView {
pictunerImageView.layer.cornerRadius = 17.5 // Cut it to a circle
pictunerImageView.image = self.pictunerImages[0]
}

// We also have an image for the pictune at the current post
if let pictuneImageView = cell.contentView.viewWithTag(1) as? UIImageView {
pictuneImageView.image = self.pictuneImages[indexPath.row]

}
}
return cell
} else {
// No pictunes have loaded yet; We probably need more time
// to load the image and audio assets for some of them
cell.textLabel!.text = "No Pictunes Available Yet"
return cell
}
}

但是当我滚动时,我看到了这个令人讨厌的背景效果:

enter image description here

我该如何消除这种影响?清除背景上下文根本没有帮助。谢谢!

最佳答案

设置:

pictunerImageView.layer.masksToBounds = true

之后:

pictunerImageView.layer.cornerRadius = 17.5

您也可以将其更改为:

pictunerImageView.layer.cornerRadius = pictunerImageView.frame.size.height *0.5

如果您想更改大小但仍希望它是圆形。

关于ios - 为什么在 UITableViewCell 中修改此 CALayer 会导致讨厌的图形故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33844540/

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