gpt4 book ai didi

swift - 在 UICollectionView 中使用自动布局绘制圆圈的正确时机

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

在每个 Collection View 单元格内,我都有一个 View ,我想将其形成一个完美的圆圈。我使用自动布局将单元格的宽度基于主视图宽度。

我的问题:有些 View 没有完美的圆。我猜这是时间上的冲突,在将这些 UIView 制作成圆圈之前我还没有设置主视图边界。我应该在特定时间绘制cornerRadius吗?其他一切都很好。谢谢!

func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize {
return CGSize(width: self.view.frame.width/3, height: 400)
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let sessionCell = (collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.cellID, for: indexPath)) as? DayCollectionViewCell {
sessionCell.circleView.layer.cornerRadius = sessionCell.circleView.frame.width/2
return sessionCell
}
}

最佳答案

您需要在这里设置

override func layoutSubviews() {
super.layoutSubviews()
self.circleView.layer.cornerRadius = self.circleView.frame.width/2
}

内部DayCollectionViewCell

关于swift - 在 UICollectionView 中使用自动布局绘制圆圈的正确时机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52077916/

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