简体   繁体   中英

How to set image width and height automatically in a waterfall view?

I am building a waterfall view just like 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:

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.

// Get your UIImage from somewhere
UIImage *myImage = ...

UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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