简体   繁体   中英

iOS Autolayout height is ambiguous for UILabel

模棱两可的警告

Height is ambiguous for UILabel (topCommentLabel)
Height and vertical position is ambiguous for UIView (commentContainerView)

In the tableview cell using

_tableView.rowHeight = UITableViewAutomaticDimension;

I have one containerView with 3 Labels in it and I want the Label's content hold up the containerView

here is my constriants

{// comment area
        [self.commentContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self.contentLabel);
            make.top.mas_equalTo(self.contentLabel.mas_bottom).mas_offset(10);
        }];
        
        [self.topCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_equalTo(0);
        }];
        
        [self.bottomCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.topCommentLabel.mas_bottom).mas_offset(0);
            make.left.right.mas_equalTo(0);
        }];
        
        [self.readAllCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.bottomCommentLabel.mas_bottom).mas_offset(0);
            make.left.bottom.mas_equalTo(0);
        }];
    }

the view displays normal but I got the ambiguous warning

Why this warning happen and How can I fix it?

You're missing vertical hugging priority . If you super view's height constraint with its content, it will need at least 1 element, in this example is a Label with higher (252) or lower (250) priority with others. Setting hugging priority to one of your label to ignore this layout warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM