Get width of a resized image after UIViewContentModeScaleAspectFit

前端 未结 6 1642
忘了有多久
忘了有多久 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:49

    in your case:

    float yourScaledImageWitdh =  attachmentImageNew.frame.size.height *  attachmentImageNew.image.size.width / attachmentImageNew.image.size.height
    NSLog(@"width of resized pic is %f", yourScaledImageWitdh);
    

    but you should also check, before, the original image proportion vs the imageView proportion, my line of code is good just in case the red area is added horizontally, not in case your original image proportion is wider than the imageView frame proportion

提交回复
热议问题