Hi I am trying to get 4 rectangles to be each 1/4 of the screen size for each IPhone size from 4 to 6.
I have tried adding constraints and setting the rectangles to equal height but still haven't succeeded.
Is there an easy way to set to set this?
Thank you
You have to add the equal heights constraint to every rectangle (from the rectangle to the view, which has the exact height of the screen), and then click on the constraint, and set the multiplier to 1:4.
Related
I am a beginner, I am trying to do an autolayout. I am trying to make the label 'HRIS' and 'Please login to continue' to be proportional to the screensize (its superview), I can do it for the login button and the image leaf as the picture above, we can see that the login button and leaf image are proportional.
for the image leaf, I do equal width with 0,1 multiplier to the superview, and then I also add 'aspect ratio' to make it proportional.
but when I apply the same way to the label, it doesn't work, as we can see the label size still the same for iphone 4s and iphone 8, maybe it is because the instrinsict content size (the font size itself) that makes it like that. I tried to apply this way, but it seems the size is still the same
I want to make it little bit smaller for iphone 4s, I also can't modify using size classes since it is in the same class
so what I have to do to make label proportional to the superview (screen size / background) ?
You can do it by setting both proportional width of the label and allow it to scale down the point size.
Set the label width to proportional width like this. It is just a regular same width constraint that you edit.
Then allow your label to scale down the point size like this. This is a property of your label.
Set different font size using variations...
Simply set up a constraint for your label's width to be equal the view's width with your desired multiplier. In my example I used a multiplier of 0.5:
I'm developing an app where I'm facing an issue to achieve one UI layout only for iPhone devices. This is the layout that I'd like to achieve:
I want to achieve overlapped views that layout should be same on every device from 5s to 7 plus.
The key is setting proportional constraints.
Start with adding a UIView to hold the 4 elements - background, man, woman and heart.
Add a UIImage for the background, and pin the edges to the edges of the view - that's the easy part.
Add a UIImage for the Man...
Set the Aspect Ratio to 1:1 to keep it square (well, round in this case).
Set the Height constraint equal to the Height of the "containing" view, but then set the multiplier to less than 1 to make it relative to the view. In this case, 0.6 is pretty close.
Set constraints for Centered Horizontally and Vertically... then set the Multipliers to keep the image left and above the centers. 0.64 on horizontal, and 0.9 on vertical work pretty good.
Add a UIImage for the Woman...
Set the Height and Width constraints equal to the Man image.
Set constraints for Centered Horizontally and Vertically... then set the Multipliers to keep the image right and below the centers. 1.4 on horizontal, and 1.2 on vertical work pretty good.
Add a UIImage for the Heart...
Set the Aspect Ratio to 1:1 (or whatever gives you the proper ratio for your heart image).
Set the Height constraint equal to the Height of the "containing" view, but then set the multiplier to less than 1 to make it relative to the view. In this case, 0.15 is pretty close.
Set constraints for Centered Horizontally and Vertically... then it will need a little adjustment o note Vertical 1.05 worked for me.
Now, you just need to set appropriate constraints for the "containing" view, and all the elements will scale and position themselves within it.
When you're all done, it should (hopefully) look like this:
I put the project up in a GitHub repo for you to look at: https://github.com/DonMag/AnotherLayoutExample
Just simple question.
How to make the size of the UILabel following device size?
for example, I have 1 label that have size 20 running on iPhone 5. Then if running on iPhone 6 the label size changed to 40. What should I do?
If you are using autolayout and you want to increase height and width of label with respect to screen size then you should simply give four constraint to label like : top,bottom,leading and trailing
If you want to increase height and with with in specific desired value, for example if you want label width exact half of screen width, In this type of case you should give constraints like : leading,top,fix height, fix width. Then, select fixed width constraint and from size inspector change it's multiplier to 0.5. so your label width always remains half of screen width. you can do same for height. and you can set different multiplier value to get desired output.
Hope this will help :)
Normally I will use ratio to define the constraint. For example, if your label height design is 40 px for iPhone 6, I will define the label constraint by setting equal height of the label and the main view. After that change the multipler of the constraint to 40:1334. The label will have exact same ratio of the screen.
I have to show an imageview in a universal app ans it's size should increase as the screen design in every devices without reducing image quality. The image given to the imageview is a static image. If I use static width and height constraints using size classes it will work. But I don't think it as the correct way. If i use width & height
Proportional to the superview, it increases the image height but image clarity reduced in ipads. Any suggestion will be helpfull.
To make Imageviewsize respect to device for universal application , you need to give correct multipler to imageview.
please follow step to get desire output,
Step 1 :- Set Aspect Ratio to your imageview . (you can also set leading and trialing top , bottom etc. and then give aspect ratio.)
Aspect ration required to maintain to set image equal width and Height (Square)
Step 2 :- Set Horizontal center and vertically center imageview . (it will be differ according to your requirement , you can also take this step as step 1 and then set aspect ratio)
Step 3 :- Set Equal height to Superview from imageview.
(Don't panic , you will get warning to update frames or constrain but don't update it)
Step 4 :- Count Accurate Multiplier.
imageviewHeight / superview's height = Accurate Multipliar
Here ,
imageviewheight = 200 , superviewheight=600 so ,
200(imageviewheight)/600(superviewheight)=0.333
(set multipler to imageview where proposanal height = superview)
Step 5 :- check output to different simulator.
I hope this detail explanation is enought to understand your question.
you can give equal height or width with superview with different multiplier. for example multiplier is 0.5 five then your height or width will be half of superview's height.
hope this will help :)
Anchor the edges of the image view as you want. so that the size of image view will change based on device. But set the mode of image view to "Aspect Fit" which will make sure the image will resize but maintain the aspect ratio. You can change mode in Attribute inspector.
Please refer Difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill?
I would like to take 4 square UIImageViews and align them from left to right at the bottom of a view. I want the images to grow in height (with the correct height/width aspect ratio) and have no spaces between the images. I want all the images to be of equal width
I seem to be having a hard time coming up with the proper constraints.
I've set all the images to Aspect Fit. I've created 8 constraints on all 4 images to have equal widths and height. On the far left and far right I've set the training space to the view as 0. I've aligned them all to the bottom of the view with a constraint of 0 as well.
This all seems to work... except that the images only grow in width and not height. I'm
hoping that as the width is calculated the image will grow proportionally in height. Any ideas?
PS: I would like to do this in Interface Builder if possible, but if code is needed, that's fine