Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Last active December 10, 2015 19:29
Show Gist options
  • Select an option

  • Save sonsongithub/4481617 to your computer and use it in GitHub Desktop.

Select an option

Save sonsongithub/4481617 to your computer and use it in GitHub Desktop.
Workaround, make UITableViewCell's indention work properly in iOS6 using Autolayout. Cited from http://stackoverflow.com/a/13893146.
-(void)awakeFromNib{
[super awakeFromNib];
for(NSLayoutConstraint *cellConstraint in self.constraints){
[self removeConstraint:cellConstraint];
id firstItem = cellConstraint.firstItem == self ? self.contentView : cellConstraint.firstItem;
id seccondItem = cellConstraint.secondItem == self ? self.contentView : cellConstraint.secondItem;
NSLayoutConstraint* contentViewConstraint =
[NSLayoutConstraint constraintWithItem:firstItem
attribute:cellConstraint.firstAttribute
relatedBy:cellConstraint.relation
toItem:seccondItem
attribute:cellConstraint.secondAttribute
multiplier:cellConstraint.multiplier
constant:cellConstraint.constant];
[self.contentView addConstraint:contentViewConstraint];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment