1
다음은 빌드하고자하는 UITableViewCell
구조체입니다.동적 컨텐츠 용 tableViewCell의 Autolayout
제목은 위의 나는 자동 레이아웃없이 UI를 생성 할 수 있어요 array.Currently에서오고있다. 그러나이 경우 동적 크기의 셀 높이를 얻을 수 없습니다.
//Second cell
case 2:{
UIView *thirdContainer = [[UIView alloc]initWithFrame:CGRectZero];
[cell.contentView addSubview:thirdContainer];
UILabel *titleLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(8, 8, 220, 20)];
titleLabel2.text = @"Features:";
[thirdContainer addSubview:titleLabel2];
NSDictionary *thirdDict = @{@"thirdContainer":thirdContainer,@"titleLabel2":titleLabel2};
[thirdContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
NSArray *thirdContainerWdt = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[thirdContainer]|" options:0 metrics:nil views:thirdDict];
NSArray *thirdContainerHT = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[thirdContainer]|" options:0 metrics:nil views:thirdDict];
[cell.contentView addConstraints:thirdContainerWdt];
[cell.contentView addConstraints:thirdContainerHT];
// Without Autolayout
int x;
int y = 10;
for (int i=0; i<_featuresArray.count; i++) {
if (i%2==0) {
x = 8;
y = y + 18;
}else{
x = 200;
}
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(x, y,160, 18)];
lbl.text = _featuresArray[i];
[thirdContainer addSubview:lbl];
}
}
그리고 테이블 뷰 셀 높이가 아래와 같이 관리 - -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==2) {
if (_featuresArray.count==1||_featuresArray.count==2) {
return 50;
}else{
float ht = _featuresArray.count;
ht = ht*25;
return ht;
}
}else{
return UITableViewAutomaticDimension;
}
}
이 어떻게 있도록이 레이블을 렌더링하는 자동 레이아웃을 사용하실 수 있습니다
내가 지금까지 할 수 있어요 무엇인가 셀 높이가 자동으로 관리됩니까?다른 모든 셀의 경우 - viewDidLoad
에 행 높이를 지정합니다. 그러나 레이블에 제약 조건을 추가하는 방법을 이해할 수는 없습니다.
_myTableView.estimatedRowHeight = 168.0;
_myTableView.rowHeight = UITableViewAutomaticDimension;
내가있는 viewDidLoad –
에 고정으로 그냥 내가보기에 UILabels에 대한 제약을 작성하는 방법을 이해하기 load.However이 수하지 않았다 짓을 설정 셀 높이의 놓친 생각 . – icodes
죄송합니다. 그러나 나는 동적 인 제약 조건과 함께 comfertable이 아닙니다. –