레이블의 제약 조건을 셀의 맨 위 아래쪽 앞과 뒤쪽과 같이 설정하고 레이블 줄 수를 0으로 설정하고 줄 바꿈 모드를 줄 바꿈으로 설정합니다. 이제이 두 tableView 메소드를 배치하여 셀 높이를 동적으로 계산하십시오. 당신이 원하는대로
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
목적 C에 대한
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
스위프트 3.0를 들어
그래서 동적으로 셀 크기를 취할 것입니다.
희망이 도움이 될 것입니다.
http://stackoverflow.com/questions/40034506/how-to-resize-table-cell-based-on-textview/40035858#40035858이 대답을 참조하십시오. –
http://stackoverflow.com/a/39888662/ 6656894 또한이 대답을 참조하십시오. @ek –