이것은 내가 제안하는 아이디어의 예입니다. 이것이 귀하를 위해 최적화 된 제품을 찾는 데 도움이되기를 바랍니다. 나는 가정 할 경우
, 데이터 소스는 다음과 같이이다 :
// array of arrays of strings
var Array : [[String]] = [
["Label1", "Label2", "Label3", "Label4"],
["Label1", "Label2"],
["Label1", "Label2", "Label3", "Label4", "Label5", "Label6"],
]
이러한 방법이 구현 될 수있다 :
func calculateExpectedHeight(withItemsCount: Int) -> CGFloat
{
let titleHeight = 32.0 // this is e.g. your Layer Conf. label
let itemHeight = 18.0 // this is for a label unit that is repeating
return CGFloat(titleHeight) + CGFloat((Double(withItemsCount) * itemHeight)) + 12.0 //twelve is just for tuning
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let dataForThisRow = Array[indexPath.row]
return calculateExpectedHeight(withItemsCount: dataForThisRow.count)
}
사용 자동 레이아웃은 테이블 뷰 셀에 레이블을 모두 제한 할 수 있습니다. 그런 다음 테이블 뷰 델리게이트에서'heightForRowAt'와'estimatedHeightForRowAt'에 대해'UITableViewAutomaticDimension'을 리턴하십시오. 이러한 것들을 제자리에두면 테이블/셀이 크기 조정을 처리합니다. – keithbhunter
모든 라벨을 tableviewcell에 제약 ?? 이걸 좀 더 자세히 설명해 주시겠습니까? –
autolayout 사용법을 읽어보십시오. 그것은 당신이 필요로하는 것입니다. [Apple 웹 사이트의 기사] (https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/) 및 [Ray Wenderlich 튜토리얼] (https://www.raywenderlich.com/115440/) 자동 레이아웃 - 튜토리얼 - in-ios-9-part-1-getting-started-2). – keithbhunter