gpt4 book ai didi

ios - 在 imageview 中快速调整图像大小

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

我在 Swift 中得到了这段代码

let image: UIImageView = {
let v = UIImageView()
v.image = #imageLiteral(resourceName: "st")
v.contentMode = .scaleAspectFit
v.frame = CGRect(x:0,y:0,width:100,height:100)
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
image.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
image.topAnchor.constraint(equalTo: view.centerYAnchor,constant:-170).isActive = true

我的目标是拥有一个宽度为 100、高度为 100 的 UIImageView,其中包含具有相同尺寸的图像。但我的图像肯定大于 100px。即使我将框架更改为 10px,图像的大小也不会改变。

最佳答案

你试过这个吗?

    image.widthAnchor.constraint(equalToConstant: 100.0).isActive = true
image.heightAnchor.constraint(equalToConstant: 100.0).isActive = true

或者,我误解了你的问题......

关于ios - 在 imageview 中快速调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45065296/

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