UIImageView does not fit my screen properly - swift

I have a UIImageView that fills up the majority of my screen, with the exception of a navigationBar at the top. On my storyboard, I am using the formatting mode titled "compact width|regular height" that is supposed to work for all iPhones in portrait mode. When I attempt to run my app on an iPhone 5c, with iOS8, the imageView does not fill to fit the screen, and appears to "spill out" of the screen, based on the size and positioning of the image within the imageView. I do not have any auto-layout constraints on my imageView, because when I attempt to put them on they enlarge and distort the image even further. I have tried Scale to Fill, Aspect Fill, and Aspect Fit, and none of those work. I have also made sure that the clip to subviews selection button has been checked, so that the bounds are clipped. If anyone can help me, I would really appreciate it. Thanks!

You can disable the auto-layout and use the autoresizing mask.
I used this on images and fixed the prob like yours that I had.

Related

How to resize the UIWebView content size on orientation?

My application has a UIWebView which consists of an UIImageView as its subview, when i change the orientation of the device, the image in UIWebView is not affected and it remains in the same position as before. So is there a way to fix this issue. i want the image to automatically allign to its respective orientation.
How about use "Size Inspector". Set as below, the image view will move to new position.
Can you see what I have done in this picture? I removed all red lines around square so that the view moves to keep ratio of distance to edge of screen.
Have a look on the autoresizingMask which defines how the view behaves if the superviews bounds changes. In Xcode you can do it in the Interface Builder/Size Inspector.

presenting same image in all orientations in fullscreen

I was just wondering how can I set up a gallery in landscape and portrait mode, and show the images as normal in both modes (not stretched or squashed). The only way I can think of is having the same image in both sizes so it can be shown the one that suits the orientation. This idea appears "dumb" to me so if someone knows a better way to set an image view in all orientations please give me some advices
Landscape and portrait are different aspect ratios. If you don't want to stretch or squash the images, you can either crop the image or letterbox it.
Cropping is where you don't show the entire image, for instance an image that covers the entire screen in portrait would have the top and bottom removed.
Letterboxing is where the entire image is shown, but with a solid colour surrounding the image. For instance, a landscape image shown in portrait would have black areas above and below the image.
It's relatively easy to do the above on the iPhone by selecting the correct content mode options in Interface Builder.
You can also supply different images as you describe, but that would just mean that you'd be cropping or letter boxing manually.
You should look at the contentMode property of your image view (or any UIView subclass, for that matter). Set it to UIViewContentModeScaleAspectFit, which will size the content of the image view to fill as much of it as possible without distorting the aspect ratio or clipping anything. In this case, just set the image view to be as large as possible, and the content mode will handle the rest.

Rotating UIView and background to landscape mode

The initial root view controller is 9 (3x3) buttons with a custom background in portrait mode. When the device is rotated into landscape mode the last row of buttons (of course) are cut off and the background (which is 320x480) doesn't fill the width of the screen.
What is the proper way of handling this? Do I need to move and resize the buttons myself? Do I have multiple Nibs? How do I resize/rotate the background?
Use shouldAutorotateToInterfaceOrientation and/or deviceDidRotateSelector in your viewController to reposition / layout & scale your views programmatically as you require.
If you set the auto-resizing masks on the buttons to have flexible margins in all directions they should reposition themselves appropriately when you rotate the device. You can do this either in code, or in Interface Builder (which has a nice little simulator demonstrating the effect)
With regards the background, what I prefer to do is to make the image the combination of the maximum proportions of each orientation, and then center it. For instance, make your image 480 x 480, make the view that houses it the same size and then use the appropriate auto-resizing masks to achieve the desired effect.

Obj-C, how to handle a background image which is squashed on some views and not others?

I've got a background image with a radial gradient, on some views it looks fine.
But on others where I have extra controls at the top of the view its squashed as it has less room to be show.
I guess I'm going to have to take account of the where the images starts at the top or the bottom, so one end will loose a section. But if I can do this via a property, rather than stretch ? or if I have to chop the image some how ?
What can I do?
Are you showing with UIImageView? Default contentmode is set to UIViewContentModeScaleToFill, which is to stretch in all directions to fit frame.
Change contentMode property to get the effect you want, ie UIViewContentModeScaleAspectFill.

trouble with rotating view (and resizing elements within) in ipad application

I'm having a nightmare with the rotation on iPad. I've searched all over the place for some tutorials, but nothing seems to really be for what I want. (Possibly not searching for the right thing?!)
I have a portrait view by default which is an image and a button inside the view. When I rotate, I detect this can work out if it's landscape. I then try to set the frame size of the uiview to fit nicely on the screen.
If I let it autoresize, it simply stretches and fills the screen. This I don't want.
but the trouble is, when I resize, the button gets resized too, but not in the same ratio as the image.
My question is: What's the best way to resize the view. I wanted to simply reduce the uiview by say 60% and it resizes EVERYTHING in that view with the same 60%. The only way I see this is working at the moment is to create two views... but that's twice the work and maintenance!
I've tried messing with the autosizing arrows in Interface builder, but that again seems to screw things up more!
I'm completely lost here!! Thanks for any info
The problem you have there is that the view is automatically resized to the screen ratio. On an iPad in Portrait Orientation the screen size is 1024x768. After the rotation to Landscape the origin rotates too and your screen content is skewed or stretched to 768x1024.
What you need to do is to override the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
message of the UIViewController of the view which rotates. This message is called within the animation block of the rotation. You just set the framesize of your subviews (the button) to whatever is best for you. Once i had a problem with rotating an OpenGL view. The content of the view was stretched when rotating to landscape. Since it is not possible to alter any OpenGL matrices within the animation block the only solution i found was to make the view quadratic and to set the origin behind the bounds of the screen (in -x direction). You have to override the message also to reset the origin above the screen (in -y direction) bounds in landscape mode, to keep the viewport in the middle of the screen. That way the view kept its ratio. Whatever solution is best for you, overriding this message should work out.
Have you tried disabling the autoresizesSubviews property on your UIView? It should prevent any size changes on the subviews when you resize your view.