Get width of a resized image after UIViewContentModeScaleAspectFit

前端 未结 6 1653
忘了有多久
忘了有多久 2021-01-30 13:56

I have my UIImageView and I put an image into it that I resize like this:

UIImageView *attachmentImageNew = [[UIImageView alloc] initWithFrame:CGRectMake(5.5, 6.         


        
6条回答
  •  星月不相逢
    2021-01-30 14:38

    I don't know is there more clear solution, but this works:

    float widthRatio = imageView.bounds.size.width / imageView.image.size.width;
    float heightRatio = imageView.bounds.size.height / imageView.image.size.height;
    float scale = MIN(widthRatio, heightRatio);
    float imageWidth = scale * imageView.image.size.width;
    float imageHeight = scale * imageView.image.size.height;
    

提交回复
热议问题