UILabels不显示除非tableviewcell autolayout中有文本

时间:2016-08-23 00:47:52

标签: autolayout

我有一个tableview单元格,我正在使用UIAutomaticDimensions功能来确保tableview单元格可以自行调整大小。单元格有3个标签和一个imageview作为其内容。现在问题在于标签及其垂直约束。除非标签中有文字,否则标签不会显示。它只是覆盖标签上面的先前位置,使得单元格非常小。我想要做的是始终显示所有三个标签,因此单元格的高度始终与另一个单元格相同。

即使标签中没有文字,我如何才能显示标签?

继承了对内容约束的探索。

[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_prospect_avatar
                                                             attribute:NSLayoutAttributeLeading
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.contentView
                                                             attribute:NSLayoutAttributeLeading
                                                            multiplier:1.0
                                                              constant:0.0f]];

[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_prospect_avatar
                                                             attribute:NSLayoutAttributeTrailing
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.contentView
                                                             attribute:NSLayoutAttributeLeading
                                                            multiplier:1.0f
                                                              constant:100.0f]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_prospect_avatar]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:NSDictionaryOfVariableBindings(_prospect_avatar)]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_prospect_avatar][_full_name_label]-|"
                                                                        options:NSLayoutFormatDirectionLeadingToTrailing
                                                                        metrics:nil
                                                                          views:NSDictionaryOfVariableBindings(_prospect_avatar,_full_name_label)]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_prospect_avatar][_phone_number_label]-|"
                                                                         options:NSLayoutFormatDirectionLeadingToTrailing
                                                                         metrics:nil
                                                                           views:NSDictionaryOfVariableBindings(_prospect_avatar,_phone_number_label)]];

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_prospect_avatar][_email_label]-|"
                                                                         options:NSLayoutFormatDirectionLeadingToTrailing
                                                                         metrics:nil
                                                                           views:NSDictionaryOfVariableBindings(_prospect_avatar,_email_label)]];

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[_full_name_label][_email_label][_phone_number_label]-10-|"
                                                                        options:NSLayoutFormatAlignAllLeading
                                                                        metrics:nil
                                                                           views:NSDictionaryOfVariableBindings(_full_name_label,_email_label,_phone_number_label)]];

0 个答案:

没有答案