Search code examples
iosobjective-cuiimageviewuiimagecgsize

Resizing UIImageView without scaling UIImage


I have a UIImageView that display a UIImage with the content mode set with UIContentModeScaleAspectFit. The imageview is as width as the screen. I want to resize the imageview without changing image position and scale. So, after resizing, the UIImage would be still virtually at the same position and still virtually as width as the screen, but not entirely visible because of the imageview resizing.

I try using UIContentModeLeft, while resizing from the right, to fix UIImage position, but my image wasn't at full resolution like when I'm using UIContentModeScaleAspectFit.

I'm clueless about this. I might need to use CGImage or CIImage, but I don't know where to start.


Solution

  • I manage to solve my problem. Here's what I did :

    • Create a UIView in which I add a UIImageView subview
    • Set the imageview content mode to UIContentModeScaleAspectFit
    • Defining imageview frame to the screen with [[UIScreen mainScreen] bounds]
    • setClipsToBounds = YES to the UIView

    Now, when resizing, the imageview is not scaling because its frame is define to be as big as the screen, setClipsToBounds: make sure I don't see part of the image that is outside of the UIView frame.