Self sizing tableview UILabel overflow

72 Views Asked by At

I'm having difficulty laying out my custom cell. I have an image view and two labels. A titleLabel and overview label.

My problem is the overviewLabel is extending outside of the cell and is inconsistent. I think this throws off the rest of the labels.

My goal is to fit the labels better to the cell and improve the layout.

My constraints are as follows.

Custom Cell Class

enter image description here

self.photoImageView.translatesAutoresizingMaskIntoConstraints = false;
[self.photoImageView.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor].active = YES;
[self.photoImageView.widthAnchor constraintEqualToAnchor:self.photoImageView.heightAnchor].active = YES;

[self.photoImageView.topAnchor constraintEqualToAnchor:margins.topAnchor].active = YES;
[self.photoImageView.bottomAnchor constraintLessThanOrEqualToAnchor:margins.bottomAnchor constant:0].active = YES;
self.photoImageView.contentMode = UIViewContentModeScaleAspectFit;
self.photoImageView.layer.cornerRadius = 17;
self.photoImageView.layer.masksToBounds = YES;



self.titleLabel.translatesAutoresizingMaskIntoConstraints = false;
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.photoImageView.trailingAnchor].active = YES;
[self.titleLabel.trailingAnchor constraintLessThanOrEqualToAnchor:margins.trailingAnchor].active = YES;

[self.titleLabel.topAnchor constraintEqualToAnchor:margins.topAnchor].active = YES;
self.titleLabel.font = [UIFont fontWithName:@"Avenir-Book" size:13];
self.titleLabel.textAlignment = NSTextAlignmentLeft;


self.overviewLabel.translatesAutoresizingMaskIntoConstraints = false;
[self.overviewLabel.leadingAnchor constraintEqualToAnchor:self.photoImageView.trailingAnchor].active = YES;
[self.overviewLabel.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES;

[self.overviewLabel.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:5].active = YES;

[self.overviewLabel.bottomAnchor constraintGreaterThanOrEqualToAnchor:margins.bottomAnchor constant:0].active = YES;
[self.overviewLabel sizeToFit];

In my viewdidLoad for mytableview I have the following

self.moviesTableView.estimatedRowHeight = 100;
self.moviesTableView.rowHeight = UITableViewAutomaticDimension;
0

There are 0 best solutions below