Scale up UIImageView (Storyboard Autoresizing) - ios

I have a UIImageView in a Storyboard. The image used is square. The imageView width and height are equivalent. I want to take advantage of Autoresizing in Storyboard, so that on a small device the image is scaled down and on a large device the image is scaled up. When I test on a iPhone 5 the scaling is appropriate. However, when running on a iPad the results are different. The square is stretched, and this makes sense as the dimensions of the screen is different to the dimensions of the iPhone. How can I avoid this issue, is there a process in which I can scale the view as a whole up until the height is the same as the height of an iPad and then centre the view?
Note - The image has the same width and height and the content mode is set to 'Aspect Fit'

Follow this procedure
1) add a view in which all your content will be added so now you going to use 2 views NewView[with Content] and baseView
now time to add constraints to newView Do like this for leading, trailing,bottom and top [adding wr hr component]
Result For iPad
result for iPhone

Related

Possible to have different behavior for landscape orientation in launch screen storyboard?

In my Launch Screen.storyboard, I have a UIImageView named LaunchScreenIcon that scales proportionally to the width of the screen by setting the LaunchScreenIcon.width = width constraint.
Is it somehow possible to change the behavior for landscape orientation so that the height of the UIImageView scales to the height of the screen i.e. LaunchScreenIcon.height = height?
Constrain your image view to 0 on all four sides (so it fills the entire view), then set its Content Mode to Aspect Fit
That should give you what you want.
I was able to accomplish this by:
Going to my Launch Screen.storyboard
Selecting the large iPad model in landscape from the panel at the
bottom
Tapping "Vary for Traits" to the right and checking off both width
and height
Then I added the constraint as I normally would and it was now only
associated with the large iPad model in landscape

Launch screen storyboard constraints in iOS Universal app

I'm working on a LaunchScreen.storyboard file for an iOS Universal app in Xcode 7.3.
I must use only constraints defined in storyboard, because the launch screen will be shown before the app will be loaded (can't configure constraints programmatically in a UIViewController subclass).
The background image in the main UIViewController has
aspect-ratio (3456:2592),
center vertically and
center horizontally constraints.
I'm trying to obtain the following conditions:
maintain the background image aspect-ratio,
activate backgroundImageView.Top = containerView.Top when screen width <= screen height
activate backgroundImageView.Leading = containerView.Leading - 20 when screen width > screen height
The problem is that storyboard constraint definition by size classes is not powerful enough to express conditions like screen width >/<= screen height (e.g.: an iPad Air Fullscreen has always regular width and height, but screen width < screen height in portrait mode and screen width > screen height in landscape mode).
I tried also to define the background image asset set by device, but it allows only to specify iPhone/iPad x1, x2 and x3 versions of the image.
You don't need auto-layout for this. Make the UIImageView fill the whole screen, then select the Aspect Fill mode for the background UIImageView.
Result:
Note that the background image (1) keeps the aspect ratio, (2) centered horizontally and vertically, and (3) automatically scale up to fit the longest axis.

UIImageView sizing in AutoLayout + Size classes for all devices

I'm working on app and will for 1st time use auto layout/size classes. Today my first day learning it and I understand constraints now and how to place the images where I want them to be on every devices from iPhone 4s to iPad PRO.
As my main storyboard in Attributes inspector i'm using INFERRED size. In show Assistant Editor, Preview, i'm using all device sizes.
In my inferred storyboard i'm using a UIImageView size 170 Width, 230 Height. Then I use AutoLayout to make it center of every device screen in preview.
Now the issue is this UIImageView covers HALF of the size of iPhone 4s preview but only about 1/5th the size of iPad PRO. How do I alter the size of each UIImageView to the size that I want them to be in each device without changing that centered position of each UIImageView in the preview devices?
You need to first set up your constraints properly and then choose the type of scaling you want.
Set up your constraints:
Click on the Pin icon |-[]-| at the bottom of the screen. Turn on all four orange I-beams. Set the four constants to zero.
Uncheck the Constrain to margins checkbox and click 'add 4 constraints'
Then set your scaling:
Click on the Image View you added to your View Controller.
In the Attributes Inspector on the right, choose your image.
Set the Mode of the View to Aspect Fill (fill entire screen cropping top/bottom or left/right as necessary) or Aspect Fit (letter box image so that entire image is shown uncrossed).
That should work
Maybe you can use a pending or proportion constraints instead of width and height constraints.

Xcode 6 UIimageview display error

Guys i have a problem. So i just make a autolayout in xcode (background image and over the background image i have a logo image uppercase and in the middle i square where i will want to import from database a random image)
As you can see in the Mainstoryboard(preview) on the 4 displays those image look exacly the same. Instead of this i would like to display them on the same way as i have on the 3rd resolution (4.7 inch), because under the image i want to put something else and on the 3.5inch is to small the space and on the 5.5 inch is to big, i want the image to be bigger...
You could add height constraint on UIImageView which displays random image relative to the height of main view (root view for UIViewController)
In IB control drag UIImageView to the root view, you will see a popup, click on Aspect Ratio. You could set aspect ratio of UIImageView height to the height of root view. You could set another constraint to make width and height equal to make it square.
This will give you space relative to height of screen below UIImageView.

how to increase the width of two image view in a main view whose sizes are different and get variation in width when changing their orientation

How do I increase the width of two image views which are located inside a main view to landscapeorientation through a UIInterface nib file from portrait orientation, where the sizes of image view are different to one another?
I need a increase in width proportional to their default size.
Explain by setting a constraint in the nib file.
example, my image view1 is in left corner of the main view and image view2 is in right corner of the main view.both of same height but width is different.first it is in portrait i am setting this in nib file.while running by changing the portrait view into landscape either any one of the sizes gets increased.but my requirement is need to expand the width of both image view from their original width size in correct ratio.for this how to set the constraint in nib file
the image for my requirement
as in portrait orientation,
and i need in landscape orientation as,
here one more doubt was that cant make correct streching size too in horizontal orientation for that orange and white (height i am mentioning here) colour image views.
Use autosizing functionality.
For more info try this link:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

Resources