Minimum cell height with UITableViewAutomaticDimension

后端 未结 6 2058
长情又很酷
长情又很酷 2020-12-28 15:21

Is it possible to set minimal height for cell? I use dynamic:

tableView.estimatedRowHeight = 83.0
tableView.rowHeight = UITableViewAutomaticDimension
         


        
6条回答
  •  星月不相逢
    2020-12-28 15:37

    At the auto layout code of the custom cell (either Interface Builder or programmatically), add the appropriate constraints.

    E.g. (Programmatically in custom cell)

        UILabel * label = [UILabel new];
        [self.contentView addSubview:label];
        NSDictionary * views = NSDictionaryOfVariableBindings(label);
    //Inset 5 px
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[label]-5-|" options:0 metrics:nil views:views]];
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[label]-5-|" options:0 metrics:nil views:views]];
    // height >= 44
        [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.mainLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:44.0]];
    

提交回复
热议问题