I'm using Masonry on table view cells, right now I have a UITableViewCell which is a container of views, something like this:
*Table View(cellForRowAtIndexPath):
MasonryTestTableViewCell *masonryCell = [tableView dequeueReusableCellWithIdentifier:@"masonryCell"];
if (masonryCell == nil) {
masonryCell = [[MasonryTestTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"masonryCell"];
}
[masonryCell addSubview:[self createViewForCell]];
return masonryCell;
*createViewForCell method(which also uses masonry):
-(UIView *) createViewForCell{
self.textLabel = [[UILabel alloc]init];
[self.textLabel setLineBreakMode:NSLineBreakByWordWrapping];
[self.textLabel setTextAlignment:NSTextAlignmentLeft];
[self.textLabel setNumberOfLines:0];
[self.textLabel setText:@"TEST TEXT"];
[self.textLabel setPreferredMaxLayoutWidth:[UIScreen mainScreen].bounds.size.width];
[self addSubview:self.textLabel];
[self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).with.offset(10);
make.bottom.equalTo(self.mas_bottom).with.offset(-10);
make.right.equalTo(self.mas_right).with.offset(-10);
make.top.equalTo(self.mas_top).with.offset(10);
}];
self.textLabel.layer.borderColor = [UIColor grayColor].CGColor;
self.textLabel.layer.borderWidth = 3;
}
*@implementation MasonryTestTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
return [super initWithStyle:style reuseIdentifier:reuseIdentifier];
}
- (void) setContent:(UIView *)view{
[self setBackgroundColor:[UIColor greenColor]];
[self addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).with.offset(kYPosition);
make.bottom.equalTo(self.mas_bottom).with.offset(-kYPosition);
make.left.equalTo(self.mas_left).with.offset(kCellPadding);
make.right.equalTo(self.mas_right).with.offset(-kCellPadding);
}];
}
The issue that I'm facing right now is that the cell doesn't risize properly, it get to a point that, if I set a long text on the textLabel, it doesn't increase the cell height, I can't fix this, do you know if there is something else that ai should do to get this working?