I have some custom cells in a UITableViewController that I've used constraints to set a label to align to the left margin with a a trailing space of 8 and a switch to align to the right margin, also with a trailing space of 8. This looks great on iPhone, but it does not align properly on iPad. Here's what it looks like.
iPhone:
iPad:
How do you set the margin to automatically change based on the screen size so it doesn't look so weird on iPad?
Absolutely nothing I tried would fix this. It turns out that there must be some bug in iOS9/Xcode 7, because I was only able to fix the issue by downgrading my devices to iOS 8 and Xcode to Xcode 6.
Related
This is my first post. I just started coding. I want to make my first simple app. I own an iPhone 5S and when I add constrains in compact width / compact width & regular height(in XCode), it shows it right on the iPhone 6S plus simulator. When I try it on my iPhone it just looks weird. I know the sizes of the iPhones are different, but how can I correct this? Now, if I code in compact width / compact width & regular height, it feels like I am coding for an iPhone 6...
I hope someone can help me.
Here is the Storyboard:
I use compact/regular size classes for portrait, and any/compact for landscape, for those two phones you mention (actually, for all of the phones).
And, (squinting at your constraints in the tiny pic), it looks to me like the constraints are "wrong" (not optimal, at least). You've got the button pinned 550 down and 280 across from the edges, which won't look right for smaller devices.
Try aligning the button to horiz and vertical centers, and it will look right everywhere.
Or pin ONE of the edges of the button, and ONE of the top/bottom edges of the button, to the layout margins on one corner. Then it will look right on all devices.
Instead of removing the trailing and bottom constraints, as #Kevin suggests, set both of their constants to 0 (or whatever's reasonable), and make them greater than or equal, not equal.
For the constraints to appear fine for different screen sizes, one possible way is to add the required constraints to your button or label or any other component and have a preview look at it in the assistant editor section.(Click on assistant editor and in the split screen that comes up, find the Automatic section and within it the preview option)This helps to view the layout of your app for different screen sizes. This helps to manage your auto layout issues by a good extent.
I have 7 labels on a cell in TableView in Landscape mode and I have set the Top Space and Leading Space on each. My issue is it is working fine with iPhone 5 screen it fit well but I get and empty space with iPhone 6 and 6 Plus screen on the right place. How I can fix that with the constraint?
Example:
iPhone 5:
iPhone 6
Please check this youtube link https://www.youtube.com/watch?v=WTMpJJ9Ofm8
In this link it is showing how to arrange vertical spacing.
You can apply same logic to "Trailing Space to Container Margin" for equal spacing. By changing the multiplier value of the constraint you can change the spacing.
I have table view cell like this in a xib file:
On iOS 8 it looks as I want, but on iOS 7 the image view on left side and view on the right side look like this:
I know about iOS 8 margins and I have made constraints without the "Constraint to margins" option.
How can I make iOS 7 table view cell similar to iOS 8?
You didn't show all the constraints. Here is an excellent auto-layout tableview sample
which will walk you through the iOS Size Classes or just refer this tutorial.
When i run the app on simulator it looks different from the view controller storyboard. I guess it is a problem with auto layout , but i don't know how to fix it. What should i do? Thank you in advance.
edit: It looks perfect in simulator iphone 5 or 5s , but it looks different if i change the simulator to iphone 4s , 6 or 6plus.
If you want to center the button in superview, select the red button, firstly go to Editor --> Align --> Horizontal center in container. Secondly go to Editor --> Pin --> Leading space to superview/Top space to super view to add top space and leading space to super view, or you can just click adding missing constraints in storyboard, which adds missing constraints.
if you have used auto layouts then make sure that margins option is not selected, as it adjusts margins and it affects the position of the control.
I'm using Auto Layout for an iPhone app to place a button footer bar at the bottom of the screen on both 3.5" and 4" iPhones. The bar is a UIView containing two UIButtons and a UIImageView.
I have a Vertical Space Constraint pinning the bottom space to the superview.
(Editor -> Pin -> Bottom Space to Superview)
It has an Equal relationship. Constant is 60, Standard is NO, Priority is 1000, and Placeholder is NO.
In iOS 7 it works exactly as expected. In iOS 6, it does not. The bar is not a consistent distance from the bottom when I switch between that view controller and its neighbors, and the buttons frequently do not work (they don't even highlight when I tap them). This is all in the simulator, I haven't tried hardware yet. The app is a legacy app, so all of the layout work is in xib files, not storyboards.
Do I need to do something different in iOS 6 to get Auto Layout to work? From what I read, it should be fully compatible with 6 & 7.
Some more information is needed to really get to the heart of the matter. Specifically how auto layout is being used to attach the bar to the bottom.
One thing that gets me over and over though, is remembering to set the translatesAutoResizingMasksIntoConstraints property to false on view(s) that utilize constraints.
Be sure to check the log output while debugging as that will indicate if you have any ambiguous or unsatisfiable constraints. At design time, XCode 4 IB will attempt to add any constraints that you are missing for you. XCode 5 IB will only tell you what you are missing and then at runtime try to add any missing constraints if it can.