All screen sizes display the app as expected except 3.5 Inches, that is always off by a long shot. What can I do to prevent this?
In Interface Builder, you'll want to set constraints for compact screen sizes. At the bottom, you'll see this:
Change that to Compact Height x Compact width and set constraints for that screen size.
Related
All iPhone devices from iPhone SE to iPhone XSMax fall under same size class of compact width and regular height in Portrait mode. Then how can we add different size for UIButton in storyboard that can vary for iPhone 5s, iPhone 6 and iPhone X?
How can we use size classes for iPhones in portrait mode? Also how can we use different font sizes for different devices?
I tried to use vary for traits in storyboard but was unsuccessful to set different heights for a UIButton in different iPhone devices.
I want to set Button to be of height 30 in iPhone 4s and I want that button to grow as the device height increases and font size also should vary accordingly. Setting button's height proportional super view's height didn't yield me desired results as there are other UIElements in the storyboard.
This can be done in a lot of different ways. You could for example
Use proportional height constraints
Not use height constraints and only constrain the distance to the screen / other elements
As the screen grows, the distance to the screen edge will stay the same, resulting in a bigger button
Set different heights for different screen sizes via code
You could wrap this into a NSLayoutConstraint subclass that has #IBInspectable properties, allowing you to set everything up using the Interface Builder
I think you should first think about your design again. Fixed heights usually break as soon as there are new iPhone sizes. Because of that, you should probably try to not have fixed heights for different phones and instead use equal distances to other elements or proportional constraints.
In my opinion most fixed heights are unnecessary and I'd consider them a code-smell.
So I have the following layout in storyboards, everything works fine on the 3x screen sizes but I would like to try and tidy up the font sizes and the position of the button icon relative to the button text.
See below what I mean, basically what I want is for each screen size to look very similar to the 4.7 screen layout e.g. the spacing between the text and the icons (also how can I get the font to scale down slightly on the 4 inch screen as it looks too big but ok on the rest of the screens.
Any idea what constraints I need to put on the icons and text to get it to look the same on each screen size.
In auto layout use multiplayer to increase and shrink the element. Please see the example below:
Now run your app and check in all device type. Hope this will work for you.
If you are using autolayout, you can set aspect ratio constraints for width and height of the imageView to the cell content view, that way, if the cell grows image will grow too.
The following link might be useful http://candycode.io/how-to-set-up-different-auto-layout-constraints-for-different-screen-sizes/
I've got all my elements in the view and have added constraints to position them correctly on any device.
But when it's run on a 3.5 inch iPhone some of the bottom stuff is cut off and when it's run on a iPhone 6Plus there's a lot of extra space on the bottom.
How could I resize all the elements to look good on all devices?
This is a universal app to run on iPhone and iPad.
I guess you constraint an element as width equals 300...It's very bad for some elements that should fill (or fill percent of) the screen. I suggest you make percentage constraints. For example, make equal width to view, click Edit button and set Multipiler 0.6. It looks like this in storyboard:
make two constraints (trailing and leading for example) and make aspect ratio for your image, maybe this will help you.
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.
I have three buttons on a screen and I am adding them to the bottom half of the screen. I am using size classes and want them same on all iPhone portrait orientations. I am adding constraints separately for Compact Width | Regular height and Compact Width | Any Height. But for one resolution the UI is not setted right and thats either iPhone 6+ or iPhone 4s. Anybody have any idea what I am doing wrong and how to design for all iPhone resolutions using size classes. It appears I have arrived at a deadlock.
Thanks in advance.
You are using size classes so have to set vertical and horizontal spacing. In Universal Storyboard there are option "Any Width Any height" and "add new alignment constraints"
See this link.
https://www.youtube.com/watch?v=G53PuA_TlXk