Self-Sizing TableView Cells based on two subview's height

旧时模样 提交于 2019-11-29 17:28:14

Give fixed height and width to the image view . Otherwise let the tableViewCell know the top and bottom of the imageview. So that it can calculate the correct cell height

First make sure that you are using self-sizing cells: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html

Make Top and Bottom constraints for both image view and the container view to the edges of the cell and make them >=.

Alternatively, you could try Horizontal Stack View and make rigid (highest priorities) constraints to each edge of the cell.

Use these delegates,

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
     return 100; // height of default cell
 }

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

Edit

Try this one.

Your view hierarchy should be like this

ImageView Constraints

Add a view and put both labels into it.

Label Container contraints

Label Title constraint

Label Description constraint

Edit Output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!