fanghai44
fanghai44

Reputation: 63

iOS stretch image to full screen

I have a scroll view with a image view inside. I was wondering whether it's possible to have the image inside the image view be much smaller than the resolution of the screen, and somehow be able to stretch it to fit the screen.

Upvotes: 0

Views: 1800

Answers (3)

Hermann Klecker
Hermann Klecker

Reputation: 14068

Your UIImageView is within an UIScrollView I understand?

That would work by adjusting the scroll view plus adusting the image view appropriately. However that is not advisable to do. You will get lost in small errors with annoying effects.

I'd suggest to add an additional UIView that can match the bounds of the screen. Add that view to the underlying "view" object and use the bringSubviewToFront method.

You could as well make sure that this new UIView is the first subview of the most underlying view object. You could achieve that by manipulating the subviews array structure - which I do not recommend in general wihout having fully understood everythng about the view hierarchy. You can as well achieve that by adding the additional view at first before adding any other view. (Within IB just make sure that the new view is the topmost in the tree, coming next to the view controllers "view".) And then make it hidden until you actually need it. Then you unhide it. When it is not needed anymore then hide it again and neither delete it nor erase it from its superview.

Upvotes: 0

artey
artey

Reputation: 1243

Set contentMode on the UIImageView and change its size.

[UIImageView setContentMode:UIViewContentModeScaleToFill];

Check the docs for more informations regarding UIViewContentMode:

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW69

Upvotes: 2

jakenberg
jakenberg

Reputation: 2113

Sure, just change the bounds of the imageView.

Am I missing something here?

Upvotes: 0

Related Questions