I'm trying to create this view where images stick together and get resized when the device get smaller. Every thing works, but the only thing that I don't seem to get to work is the scale down.
As you can see from the screenshot there are two boxes that need to be centered. The space between the boxes always remains the same as do the width and height (e.g. 100x100 or 50x50 or 25x25 etc.). But it's this simple resize where the boxes get smaller that doesn't work. Do you guys have any clue what kind of auto layout property I should use? Or the combination of properties? Help is much appreciated.
Regards
You can do this all in the storyboard. Give the views whatever spacing you want to the left and right edges, as well as a space between them. Select the 2 boxes, and choose "Equal Widths" and "Equal Heights". Choose one of the boxes, and give it a aspect ratio constraint of 1:1. Don't give the boxes any fixed width or height constraints.
I am absolutely agree with #rdelmar answer ... +1 for the answer...
Actually for a maintain ratio of any object you need to use aspect ratio like 100x100 in bigger screen and 50x50 in smaller screen...same for other view sizes...
and as we want both object to be same in terms of height and width, we have to give equal width and height of one object to another...
For a better understanding how it done ...here is the visual format..
And Here is the output as you want...
Related
Suppose i have a View controller in which there are two labels and they have 112 vertical spacing between them for iphone 6 plus. If i want to keep this spacing for all types of devices as a aspect ratio, what will be the proper way?
Currently i am following one of two approaches.
1. Stack View approach:
In this approach i am taking
a. A stack view
b. Put that two labels into that Stack View
c. set spacing from storyboard.
d. multiply this spacing with the device aspect ratio. like this
#define SCREEN_RATIO_RESPECT_OF_IPHONE_6P (SCREEN_MAX_LENGTH/736.0)
2. Normal Constraint Approach:
Multiply vertical spacing(in my case 112) with the device aspect ratio just like approach 1.
But what is actually the better way to handle this type of problem?
For your view to remain visually consistant across devices I usually convert my design specs into relative or percentage based sizes.
So for example, if you have a button at the bottom of the screen that is supposed (as per design) to have 24px of space from the bottom and side edges of the screen. I would look at the design and work out 24px as a percentage of the width of the screen (in the design). This would mean that the spacing/padding is consistent on all devices.
In regards to fonts, I would usually set the font size as per design but where possible I would allow it to reduce the size to fit using adjustsFontSizeToFitWidth and minimumScaleFactor like in UILabels.
Hope this helps
I have some problems with positioning labels on top of the image for different screen sizes. Image size changes depending on the screen and labels must be accurately in some places over image. I read about adaptive interfaces and size classes, but linking to constrains is not accurately positioned labels and I do not know what to do. I will be very grateful for your help!
Something like this
Add two constraints to each label to fix it to the two edges of the image it needs to stay with. Then add constraints to the labels to fix their height and width. Check that the images also have constraints to fix their positions.
Please use Auto Layout if you are not using.
Arrange the label relative to the Image on the screen.
Use Label.center or Label.frame attributes.
Hope it helps..
I've been asked to implement something like this:
where it's a horizontal scrollview that could contain several images with different aspect ratios.
So I'd probably want to add an imageview to the scrollview for each image, but I'm not sure how I should fit the images to the imageviews.
Should I set the imageview's width to the width of the image and then set the mode to scale to fill?
I don't want to just aspect fill because I don't want to cut parts of the images off, and I don't want to aspect fit because I don't want blank space.
Does anyone know how to approach this? I know it's going to be a headache trying to get every image size to work, so if anyone has experience with this, I'd appreciate the help.
Use a UICollectionView, and calculate the right image width for all cells in sizeForItemAtIndexPath.
you could make all the UIImageViews to have equal heights (the height of your UIScrollView) and set the UIImageViews' aspect ratios to the aspect ratios of the UIImages they contain. then you can set the UIImageViews' contentMode property to scaleToFill without a problem...
I'm new to iOS development and am struggling with interface builder to layout a view that has 3 images. I want three images going across the view. So the images will need to be scaled a little differently for different devices. I am hoping to do this with constraints. I am fairly close. Here is a screenshot:
The images are actually resizing and becoming bigger on the larger device screens which is what I want and the spacing is working to stop them from overlapping each other on small devices. I just need to stop the two side images from being stretched tall. I don't want to specify a height constraint because they do need to resize for specific devices sizes. Any help to add a constraint that will make the outer images not stretch tall is much appreciated.
Set the UIImageView 's content mode to be aspect fit. It will be always stretched in it's correct aspect ratio
Instead of Scale to Fill select Aspect Fit
I have an image that I want to align with the bottom right corner of the View and then I want the rest of the image to scale to fill the available space but without falling off screen.
My image is a square, so I don't want the width of the image to be any greater than the device's shortest side (portrait or landscape).
I'm new to Size Classes, but no matter what constraints I apply, the image grows bigger than the view and seems to have a gap between the bottom and right had edges of the screen, even though I've set those constraints to 0.
Your specifications are a little unclear, which may account for the difficulty you're having; you need to be very clear on exactly what you want. I had no trouble making a square image be square and fill the shorter dimension exactly in both orientations:
So if that's what you want, it's easily achieved with constraints (no size classes involved).