Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UIImageView的角半径不适用于具有动态大小的UICollectionViewCell_Swift_Uicollectionview_Uiimage_Uicollectionviewcell - Fatal编程技术网

Swift UIImageView的角半径不适用于具有动态大小的UICollectionViewCell

Swift UIImageView的角半径不适用于具有动态大小的UICollectionViewCell,swift,uicollectionview,uiimage,uicollectionviewcell,Swift,Uicollectionview,Uiimage,Uicollectionviewcell,我有一个由UIImageView组成的单元格,它的高度是单元格大小的70%,其余的30%被标签用完了 单元的动态大小根据设备宽度计算 我已经确保单元格是方形的,并且单元格中包含的UIImageView的高度和宽度的比例也为1:1 我正在集合视图的cellForItem委托方法中设置UIImage的角半径 cell.userImage.layer.cornerRadius = cell.userImage.bounds.width / 2 cell.userImage.clipsToBounds

我有一个由UIImageView组成的单元格,它的高度是单元格大小的70%,其余的30%被标签用完了

单元的动态大小根据设备宽度计算

我已经确保单元格是方形的,并且单元格中包含的UIImageView的高度和宽度的比例也为1:1

我正在集合视图的cellForItem委托方法中设置UIImage的角半径

cell.userImage.layer.cornerRadius = cell.userImage.bounds.width / 2
cell.userImage.clipsToBounds = true

那么,有谁能给我指出正确的方向,解释为什么会发生这种情况? 我应该在什么时候设置单元格生命周期中图像的角半径


如果我给出图像视图静态大小,则不会发生这种情况,但我希望大小根据屏幕大小动态变化

您使用的是“边界”宽度。尝试获取cell.userImage的宽度/高度

cell.userImage.layer.cornerRadius = cell.userImage.bounds.width / 2

还有,图像的比例是1:1吗

尝试
cell.userImage.layer.maskToBounds=true


最好将imageView包装在UIView中。然后设置UIView属性
bound.size.width/2

粘贴到此处时出错,在我的代码中,我正确使用了UIImageView的边界。。。。。。是的,比例是1:1