iOS: Dynamic Height For UITableViewCell

前端 未结 3 356
故里飘歌
故里飘歌 2020-12-20 21:43

I\'m using iOS9 XCode7 I need to change the height of cell Dynamically according to labelText Height

I have used:

self.tableView.ro         


        
3条回答
  •  醉梦人生
    2020-12-20 22:06

    Give your label constrains relative to the cell, top, bottom, left and right.

    Than your cell size will grow with the content height.

    also make your label multiline.(by setting Lines property to 0 in attribute inspector)

    #pragma mark- Menu table Delegates 
    
    -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        return UITableViewAutomaticDimension;
    }
    
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        return UITableViewAutomaticDimension;
    }
    

提交回复
热议问题