gpt4 book ai didi

ios - 如何忽略 Storyboard上的 UICollectionViewCell 大小?

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

我在 Storyboard上有单元格大小:
Screenshot1
但是我想根据设备的屏幕大小在代码中设置单元格大小,然后调用下一个委托(delegate)方法:

extension GraphicsViewController: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 0.675 * self.view.frame.size.width, height: 0.625 * self.view.frame.size.height)
}

}

我调用这个单元格的方法:

func draw(coordinates: [CGPoint]?) {
let width = self.temperatureGraphicView.frame.size.width
let height = self.temperatureGraphicView.frame.size.height
temperatureBackGroundView.layer.borderWidth = 2
temperatureBackGroundView.layer.borderColor = UIColor.black.cgColor
temperatureBackGroundView.layer.cornerRadius = 10
humidityBackGroundView.layer.borderWidth = 2
humidityBackGroundView.layer.borderColor = UIColor.black.cgColor
humidityBackGroundView.layer.cornerRadius = 10
let verticalLines = setFramesArrays().0
let horizontalLines = setFramesArrays().1
for i in stride(from: 0, to: verticalLines.count - 1, by: 2) {
drawFrame(fromPoint: verticalLines[i], toPoint: verticalLines[i + 1], graphicNumber: 0)
drawFrame(fromPoint: verticalLines[i], toPoint: verticalLines[i + 1], graphicNumber: 1)
}
for i in stride(from: 0, to: horizontalLines.count - 1, by: 2) {
drawFrame(fromPoint: horizontalLines[i], toPoint: horizontalLines[i + 1], graphicNumber: 0)
drawFrame(fromPoint: horizontalLines[i], toPoint: horizontalLines[i + 1], graphicNumber: 1)
}
}

我的 View 框架基于 Storyboard上单元格的框架,而我的网格绘图不正确:
Screenshot2

当我重新加载集合中的数据时,我有这个:
Screenshot3
我的问题是如何忽略 Storyboard上的单元格框架并以编程方式设置它?我可以用输入 View 框架做什么?

最佳答案

我假设您在 collectionView(collectionView:indexPath:) 数据源方法中调用 draw 函数。您必须调用 cell.layoutIfNeeded() 行以使用新大小重新布局单元格中的所有 subview 。

关于ios - 如何忽略 Storyboard上的 UICollectionViewCell 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49494376/

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