I am using autolayout in a UICollectionViewCell. Super simple layout: only UILabel. I want UILabel to occupy the entire width minus 20 pixels of the insert and center in the cell both vertically and horizontally. I have set limits that do just that. If I run it on any iOS 8 device or simulator, it works great. However, when I run it on some ios 7 devices, the restrictions do not affect. I tried looking at Apple documents, but none of their changes seemed to be related to the auto route.
Here's the source code for the XML, although I doubt it means a lot:
<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 workaround than answer: but I added restrictions to the 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]];
For it to work, I need both coded constraints and IB constraints. Dunno why!
source share