Xcode 6 UIimageview display error - ios

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.

Related

Fixed Button Position Relative to ImageView in Xcode

In my project I would like to essentially 'Pin' a button to a certain position on an image. The imageView scales to the screen size from the centre and maintains its aspect ratio.
I am trying to make it so that each button remains over the chakras "coloured icons in centre of body". I need them to maintain a scale that is the size of the chakras and maintain their position over the chakras regardless of screen size.
Wanted Result
Current Result
Scaling Settings
Aspect Settings
Here's an example - you will want to play with the exact positioning, but this should show you the method. You can do everything using auto layout in Xcode.
I took one of your images, and edited it to remove the buttons, and used it as the image in a UIImageView filling the screen of a UIViewController
Then I created 7 small buttons, and added constraints to them width & height = 20, and Align Centre Y to Image View
The tricky part is to add a constraint to align the centre of each button to a fixed percentage of the UIImageView centre - and that will be trial and error until it looks right.
Here's how to set the constraint
here's the app running on the iPhone 12 simulator
and here it is on an iPad (12.9 inch)
and here in landscape
You can take parent containerView for each imageView and Button.
Please see the picture to this link for better understand.
https://ibb.co/dsTjxbw

How to maintain the aspect ratio of the UIImage placed at the top to the view?

In storyboard i am placing an UIImageView for the purpose of placing the profile picture. So this image is entirely at the top of the UIView.For this i have set the constraints like this:
Preview in iPhone7:
Preview in iPhone7plus:
The problem is that though the UIImage is correctly placed at the top centre but it is not growing in size as the screen size increases. So i think i need to reset the UIImage constraints for that . How to achieve the same?
The problem is you have set explicit constraints for height and width to each be 100.
What I would suggest is making a constraint which sets the width of your image view to be equal to the width of the main view. Then set the multiplier on that constraint to be something like .25 (or whatever works best for you). This will make the width of your image view always be 25% of the width of the view, so it will be larger on larger devices. Like so:
After setting that constraint, you should add an aspect ratio constraint for the image view (drag across the image view and let go, the select "Aspect Ratio"). Set that multiplier to be 1:1 and your image view will be a square.

Scale up UIImageView (Storyboard Autoresizing)

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

How to set AutoLayout constraint of UIimageView with UIButton?

This tree include the cicle is a UIImageView's image, but the text in the circle is a UIButton. When the device is changed, like iPhone5 change to iPhone6 Plus, the image with scale to big. The Button always move to the circle's outSide. How to Solve the problem?
Autolayout has a feature called propotion. It means that by selecting any 2 UI objects you can set propotion between them for any constraint such as width, height, etc.. In tour case also select imageview and button then move to the constraints view, double click on any objects width constraint i.e either button width or image width. There you can find a option called propotion. As per your requirement you want to have a button always inside the image view, means that buttom propotion should be less than the imageview propotion. So you can set 2:3, means button width is 2/3rd part of the imageview. Now button will be always part of the imageview irrespective of the device which you run.
You can Add proportional width and height constraints to your buttons relative to imageView like this screenshot
Here I have not added fixed height and width constraints to imageview, because image view takes width and height from its content i.e from image provided to it, if you want to fix height and width of image view then you can provide those too.

AutoLayout - Keep Ratio of Image With Horizontal Constraints (Swift Xcode 6)

I've been trying to implement a timeline of picture (as instagram or facebook).
However, I've been struggling with the ratio of the image.
Here's my xib that contains my Cell :
I want the picture to keep its ratio and to completely fill the width of the cell.
I've set 4 autolayout constraint on the UIImageView as 0-0 for horizontal constraint and 5-5 for top/bottom constraints. I've also set the ViewMode to "Aspect Fit".
I've tried different setup :
set the height of UIImageView to a specific value :
--> The width of the image is modify to keep the image ratio
don't set the height of UIImageView
--> it considers that the height is equal to 0 and therefore doesn't even display the image
set the height greater or equal to a specific value :
-- > same behavior as 1. (The width of the image is modify to keep the image ratio)
I'm loading the image from an URL so I've been using the lib Haneke (https://github.com/Haneke/HanekeSwift) with the following function :
imageView.hnk_setImageFromURL(url).
It has an automatic resize of the image and I don't know how to get the original width/height of the image to set the height manually.
Again, what I want is the picture to keep its ratio and to completely fill the width of the cell.
Anyone has a suggestion ?
Thanks a lot !
This is the setup I came up with. It's a quick and dirty demo, but I would assume you'd want the image to always be centered. You can set the Horizontal and Vertical Center Constraint in storyboard to always keep it centered
If you want it to always completely fill the view, you can replace Equal Height with Equal Width, but by doing so, the imageView will run off the screen on some sizes because of the aspect ratio constraint
I've also included screenshots of the view at different sizes

Resources