0

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;
mparrish91
  • 101
  • 3
  • 11
  • For your overviewLabel set overviewLabel.bottomAnchor equal to margins.bottomAnchor – Aakash Dec 17 '16 at 04:22
  • thank you that fixed it. however when i reload my data/ refresh tableview the same problem will occur with the label changing and extending over the tableview. – mparrish91 Dec 17 '16 at 05:01
  • Where did you place this code? – Bista Dec 17 '16 at 05:14
  • The reload code? I added a refresh control in my view did load. I also reload in scrollviewdidscroll. Sometimes when i switch tabs the label is also out of the view – mparrish91 Dec 17 '16 at 05:18
  • I just put a constant height/width on my image view and constrained the label to the bottom of that image view. seems to be ok – mparrish91 Dec 17 '16 at 05:23
  • No the Autolayout code. – Bista Dec 17 '16 at 06:19
  • Tableviewcell viewdidlayoutsubview – mparrish91 Dec 17 '16 at 06:22
  • Already mutliple developers given answer of this same question [http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights) – dahiya_boy Dec 17 '16 at 07:44

0 Answers0