I am using autolayout within a UICollectionViewCell. Super simple layout: just a UILabel. I want the UILabel to take up the full width minus a 20 px inset and be centered in the cell both vertically and horizontally. I have set up constraints that do just that. If i run it on any ios 8 device or simulator it works perfectly. However, when I run it on some ios 7 devices the constraints have no effect. I tried looking through the apple docs, but none of their changes seems to be around auto layout.
Here's the XML source code though I doubt it means much:
<constraints>
<constraint firstItem="OIc-cg-9hO" firstAttribute="leading" secondItem="Ga6-nx-lOn" secondAttribute="leading" constant="20" id="A7U-sd-fcL"/>
<constraint firstAttribute="centerY" secondItem="OIc-cg-9hO" secondAttribute="centerY" id="G9e-9W-aDS"/>
<constraint firstAttribute="centerX" secondItem="OIc-cg-9hO" secondAttribute="centerX" id="TrB-hI-7Kw"/>
<constraint firstAttribute="trailing" secondItem="OIc-cg-9hO" secondAttribute="trailing" constant="20" id="yjH-nf-D9U"/>
</constraints>
More of a workaround than an answer: but I added the constraints in code as follows:
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:-20.0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0.0]];
In order for it to work I needed both the coded constraints and the IB constraints. Dunno Why!