Skip to content

Instantly share code, notes, and snippets.

@lucaspang
Created January 8, 2016 02:00
Show Gist options
  • Save lucaspang/c5102b024c86cd879d04 to your computer and use it in GitHub Desktop.
Save lucaspang/c5102b024c86cd879d04 to your computer and use it in GitHub Desktop.
iOS Base UITableViewCell, prevent autolayout issue
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.baseView = [[UIView alloc] init];
[self.baseView setBackgroundColor:[UIColor whiteColor]];
[self.contentView addSubview:self.baseView];
PREPCONSTRAINTS(self.baseView);
ALIGN_TOP(self.baseView, 0);
//Fixing the constraint issue at : http://stackoverflow.com/questions/25059443/what-is-nslayoutconstraint-uiview-encapsulated-layout-height-and-how-should-i
// ALIGN_BOTTOM(self.baseView, 0);
INSTALL_CONSTRAINTS(DEFAULT_LAYOUT_PRIORITY - 1, @"Align View", CONSTRAINT_ALIGNING_BOTTOM(self.baseView, 0));
ALIGN_LEFT(self.baseView, 0);
// ALIGN_RIGHT(self.baseView, 8);
INSTALL_CONSTRAINTS(DEFAULT_LAYOUT_PRIORITY - 1, @"Align View", CONSTRAINT_ALIGNING_RIGHT(self.baseView, 0));
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment