What would be causing the following warning (and subsequent alignment issues on iOS 7)?
Attribute Unavailable: Layout attributes relative to the layout margin on iOS versions prior to 8.0
None of the posted answers solved the problem for me. But the reason for this is the following: Xcode 6 creates constraints based on relative margins by default. Those are only available on iOS 8.0 and newer. You get these warnings when your deployment target is set to iOS 7.0 or lower.
The way I fixed the warning:
- Click the warning in Xcode
- Attribute inspector will open the constraint
- Search for item that has margin (see screenshot)
- Turn off Relative to margin option
Disable “Prefer margin relative”
Unchecking the “Prefer Margin Relative” checkbox will keep you from getting into the situation where you get this warning.
If you are like me and you built an entire app with constraints before realizing the problem, then things are a bit tougher because Xcode will not easily tell you which constraints are a problem.
In order to avoid rebuilding all of my constraints, I resorted to looking at the actual .storyboard file and I looked for constraints like this:
<constraint firstItem="vId-..." firstAttribute="top" secondItem="In7-..." secondAttribute="topMargin" id="C0H-..."/>
Notice “topMargin”. The attributes ending in “Margin” cause the warning. I went through and identified the constraints in the file this way, then I removed and re-created them in IB. After that, this warning went away.
I suspect this should also resolve some inconsistencies between iOS 7 and iOS 8 constraint handling, although I am still encountering some differences in behavior, even after addressing all Xcode warnings.
I’m currently in the same situation as I’m creating an app in Xcode 6 that targets iOS7 and 8. That warning appears because the constraints relative to the margin aren’t available in iOS7, but they are created by default in Xcode 6.
You can absolutely go back and edit the constraint to not use that ‘Relative to margin’ feature as suggested by the other answers to this question.
When creating new constraints, I hold down the Option key when choosing which kind of constraint to create. This gives me the ability to create a constraint that’s not based on the margin right away so I don’t have to go back and fix it afterwards.
Xcode 6 creates constraints based on relative margins by default.
So, if you want to force remove all baselines attributes and don’t want to search all bad constrains in Interface Buidler, to support iOS 7, I can recommend this way
To find and remove all dummy strings with “Baseline” in constraints you can do this:
- Close Xcode
- Open your stroyboard file in your favorite text editor, that supports regexp.
- Find and remove from storyboard file all strings by pattern:
- Now save file and open it in Xcode
- Fix all appeared misaligns: find all warnings and press “Update constraints for all views” to save original position of all views.
I found that “baseline” constraints causes crashes also, but Xcode doesn’t show any warnings about these constrains!
To fix it – remove from storyboard file all strings by pattern:
I took a non programmer approach.
I knew which view controler was causing the 8.0 margin message. So, I went to my constraint list. I had 33. I’ve remove every one that was causing the 8.0 margin message. I went down to 20 (So 11 was problem).
Select 32 over 33 delete and see the result. Select 31 over 33 delete and so on … Naturally when the message still there … delete the problematic one.
So it took me 5 minutes to resolve the error message.
Other constraint messages did appear but that’s not a big deal.
Ok than, redo and resolve step by step the constraint messages but this time check that all the constraint you add don’t provoke the reappearing of the 8.0 margin message. If so, undo and take an other strategy when adding constraints. There’s always an other way to add a constraint that work.
That’s not what is proposed by Xcode but it will do the job.
At the end, your done.
If you have more than one view controller, and don’t know witch one is causing the 8.0 margin message, try to isolate each view controller. May be in a separate test project with a copy and paste or deleting all the other view except one and se the result.
Using the “Create Snapshot” in the file menu can help you if something goes wrong.
Suppressing the warnings: I went through all IB constraints and deleted all that said “First Baseline…”. This made all of these warnings go away. However, IB will reintroduce the warnings if you “Add missing constraints” or “reset to suggested constraints”.
Possible cause: From a fresh Xcode 6.1 project, I copy/pasted ViewControllers in Storyboard (lazily), using “reset to suggested constraints”. Then changed the project target from 8.0 to 7.1. This caused the warnings to pop up. I noticed that the warnings only occurred on certain of my ViewControllers, which I believe were the ones I copied/pasted in Storyboard.
Suggestion: If targeting 7.1, set it up front before using IB. Don’t copy/paste view controllers in Storyboard. And be wary of “new warnings” when working within IB, so hopefully we can confirm the cause of this annoyance.