22

What's causing this warning in the interface builder?

Attribute Unavailable Layout attributes relative to the layout margin on iOS versions prior to 8.0.

I'm using the XCode 6 Beta. The warnings are pointing to lines in the xml source that do not concern attributes.

GLee
  • 5,003
  • 5
  • 35
  • 39

5 Answers5

37

Since I had already created the constraints, the answer was to click on the constraint, and then look in the Utilities bar (on the right). As shown in the picture below, click on an item and then make sure that "relative to margin" is unchecked.

Relative to margin screenshot

GLee
  • 5,003
  • 5
  • 35
  • 39
  • see comment #3 by @Matt-Gibson to this answer http://stackoverflow.com/a/25261327/2147244 – Sergey M Sep 20 '14 at 05:33
  • you'll have to adjust the constant if you do this because it will shift your views by the amount of pixels of the margin spacing. – Joris Weimar Oct 16 '14 at 14:43
  • @GLee, you saved me. I had "relative to margin" checked on a couple constraints. When I changed the constraint to 0, it would adjust the view by 16/-16. When I fixed that, it would change the constraint. That option can be set on the first or second item. Removing it solved my longstanding constraint problems. – Dan Loughney May 08 '15 at 20:44
13

When you add constraints in Xcode 6, you have the option "Constrain to margins" which create a different constraint and can't be read, for example, in Xcode 5. Create the constraints without this options and the warnings should go away. This constraints will be available on iOS 8.

enter image description here

If you have already created the constraints, we can change it clicking on the constraint and editing it. When selecting the second item, you can uncheck the "Relative to margin" option (as explained in the GLee answer.

Tchelow
  • 593
  • 4
  • 15
  • 1
    You can also override this feature for individual constraints when creating a constraint by control-dragging in IB. Once you've control-dragged and have the menu up that shows your possible constraints, hold down Option. That will change, e.g. "Leading Space to Container Margin" to just plain "Leading Space to Container". Might be helpful if you just want to do this for the occasional constraint rather than changing the default. – Matt Gibson Aug 21 '14 at 11:31
  • 2
    By the way there is no such option as "prefer margin relative" on Xcode 6. It is Fantastic how crappy xcode is. I have created the constraints automatically by selecting "reset to suggested constraints" and the constraints created by xcode have this problem. Xcode has to be burn in a ceremony with a full moon and offered to the gods of incompetence. Probably they will return such a wonderful gift. – Duck Sep 11 '14 at 12:09
  • I would suggest you add this option as well as it's preferably the first thing somebody should try – Lucas van Dongen Sep 11 '14 at 14:34
  • I updated the info and image to show the right field name as Apple changed it in the last version of Xcode (GM ATM). – Tchelow Sep 12 '14 at 01:44
  • 1
    @Matt Gibson, awesome tip dude, I've been manually removing relative to margin settings / adjusting constraints this whole time. That's going to be a huge time saver. – Adam Eisfeld Jan 27 '15 at 18:07
11

If you can't find where the warning is coming from you can use this grep to find it.

Run this in Terminal in your project directory:

grep -C 6 -nr Margin .

The 6 says how many lines of context to show before and after the match.

Collin
  • 6,720
  • 4
  • 26
  • 29
  • 1
    I replaced Margin with trailingMargin, topMargin, leadingMargin and bottomMargin for much better results in finding where the hidden warning is coming from. – Nur Iman Izam Sep 30 '14 at 06:38
  • 5
    You can also right click on your storyboard file inside Xcode's Project navigator and select Open As -> Source Code. Then just search the file for "Margin" as Collin stated. – Gasper Oct 03 '14 at 20:10
3

As per Gasper Kolenc opening the storyboard as Source Code is very useful. Here is a bit more info from my experience fixing this problem:

  1. In the storyboard source code search for "margin".You will see a line such as this.

    constraint firstAttribute="trailingMargin" secondItem="Pgb-8w-IHT" secondAttribute="trailing" constant="8" id="nKP-uZ-7Xm"/

  2. Find the id of one of the attributes (Pgb-8w-IHT in the example above).

  3. Scroll up to find in which object this constraint belongs. Something like:

    tableViewCell contentMode="scaleToFill" selectionStyle="default"

  4. Switch back to storyboard view and show the identity inspector window.

  5. Search through the subviews of the object you found above to find the id (Pgb-8w-IHT) on the identity inspector.

  6. Once found inspect the constraints to find the one that needs to be deleted and recreated without the constrain to margins option selected (use the constant=" " as a hint".

Kevin Kaiser
  • 183
  • 8
-2

In my case, I had to uncheck the "Use Auto Layout" from my storyboard in the File Inspector, and redo all the constraints in my app, the old way with that shrinking / enlarging red rectangle.

Size Classes were already disabled and the target is IOS 7.1.

But think well if you have too many View Controllers, and had already made all your constraints. When you disable auto layout, Xcode clears all the automatic constraints and reverts to the old model. Then you have to do all the job again.

This was the only way I get rid of that Attribute Unavailable warning.