[英]How to set image width and height automatically in a waterfall view?
I am building a waterfall view just like pinterest. 我正在像pinterest一样构建瀑布视图。 Now I have to explicitly set the width and height of each image, is there a way to let image autofill the suitable width and height?
现在,我必须显式设置每个图像的宽度和高度,有没有办法让图像自动填充合适的宽度和高度?
According to the UIImageView
Class Reference , under initWithImage:
根据
UIImageView
类参考 ,在initWithImage:
下initWithImage:
This method adjusts the frame of the receiver to match the size of the specified image.
此方法调整接收器的帧以匹配指定图像的大小。 It also disables user interactions for the image view by default.
默认情况下,它还会禁用图像视图的用户交互。
If your image is in a UIImage
object, calling initWithImage:
should create a UIImageView
with an appropriately sized frame for your picture. 如果您的图像位于
UIImage
对象中,则调用initWithImage:
应该会为您的图片创建一个UIImageView
并带有适当大小的框架。
// Get your UIImage from somewhere
UIImage *myImage = ...
UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.