Dynamically increase height of UILabel & TableView Cell?

前端 未结 7 1745
广开言路
广开言路 2020-12-01 12:52

I have a UITableView in which i am displaying a custom cell.I my cell i have two label & one view as below in picture.

I have given constraint of left v

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 13:08

    Give your label constraint as top to Cell , Bottom to cell and keep your Leading and trailing constraint as it is. In

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

    by using UITableViewAutomaticDimension will grow your tableview cell height according to your label's content and most important point is , select your label then go to Identity Inspector and in number of lines , write 0

提交回复
热议问题