UIImageView aspect fit and center

前端 未结 10 945
执笔经年
执笔经年 2020-12-07 09:48

I have an image view, declared programmatically, and I am setting its image, also programmatically.

However, I find myself unable to set the image to both fit the as

10条回答
  •  春和景丽
    2020-12-07 10:19

    Just pasting the solution:

    Just like @manohar said

    imageView.contentMode = UIViewContentModeCenter;
    if (imageView.bounds.size.width > ((UIImage*)imagesArray[i]).size.width && imageView.bounds.size.height > ((UIImage*)imagesArray[i]).size.height) {
           imageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    

    solved my problem

提交回复
热议问题