简体   繁体   English

如何在iOS中为图像提供宽高比

[英]How to give the aspect ratio to images in iOS

I've created the image view and set the image dynamically based on the API response. 我已经创建了图像视图,并根据API响应动态设置图像。 I've set the image and constraints programmatically and didn't use any storyboard files. 我以编程方式设置了图像和约束,并没有使用任何故事板文件。 Currently I am setting the content mode of the image view. 目前我正在设置图像视图的内容模式。 Now I want to set the ratio value to 21:9 to the image programmatically. 现在我想以编程方式将比率值设置为21:9。 Is that possible to give the ratio value to the image? 是否可以给图像赋予比率值?

Thanks in Advance! 提前致谢!

你可以使用:

imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: 21/9).isActive = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM