gpt4 book ai didi

swift - Collection View 中的 ImageView 必须居中且宽高比适合快速

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

我尝试在 Collection View 中的 imageView 中以中心和宽高比配合,但不在 Collection View 中执行任何操作。请任何人帮助我

imageproduct.center = self.viewImage.center
imageproduct.contentMode = .scaleAspectFit
self.viewImage.addSubview(imageproduct)

最佳答案

您是否尝试过在添加到 subview 后为其提供 centerX 和 centerY 约束?

imageproduct.translatesAutoresizingMaskIntoConstraints = false
imageproduct.centerXAnchor.constraint(equalTo: self.viewImage.centerXAnchor).isActive = true
imageproduct.centerYAnchor.constraint(equalTo: self.viewImage.centerYAnchor).isActive = true

还要确保您的 self.viewImage 也受到适当的约束。

关于swift - Collection View 中的 ImageView 必须居中且宽高比适合快速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58606249/

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