user2858284
user2858284

Reputation: 71

How I can pinch zoom UIImage without using UIImageView?

I have UIImage and I want to scale it without setting it into UIImageView. How I can do that ?

Upvotes: 0

Views: 718

Answers (2)

Marcel Puyat
Marcel Puyat

Reputation: 325

If what you wanted was to change the size of your UIImage, I answered this here: set size of an image programatically

Simply do this:

// Given a UIImage image and a CGSize newSize:

UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Your scaled image is now in newImage

Upvotes: 0

Keller
Keller

Reputation: 17081

As @rckoenes mentioned, UIImage is simply an image object, it does not handle display, which is precisely what UIImageView is for.

For pinch zooming an image, the easiest way is to add a UIImageView as a subview to a UIScrollView.

Upvotes: 1

Related Questions