Record a problem of incomplete display of label text caused by Masonry adding constraints

The problem is as shown in the picture, the text in the blue label is not fully displayed, and there is "love" behind it.
Please add a picture description

The reason is that when we use the masonry layout, there will be a slight error in the width, which leads to the fact that the
constraints we actually added are smaller than we expected, which makes it impossible to accommodate the expected text width in the horizontal direction, resulting in the inability to fully display

height calculation
Please add a picture description

add constraintsPlease add a picture description

Please add a picture description
Repair method

Use frame layout

- (void)layoutSubviews
{
    [super layoutSubviews];
    /*这里之所以使用frame 设置 descLabel的布局,是因为在使用maronry的时候,遇到过一个bug,
     使用masonry 添加约束, descLabel 的宽度, 略小于 SCREEN_WIDTH - 60*rectScale()
     导致我们计算高度使用的高度和实际展示的宽度不一致,就会造成UI问题
     */
    if (!isBlankString(self.listBO.summary)) {
        CGFloat sumHeight = heightForAttributeStringWithLabel(self.descLabel.attributedText, SCREEN_WIDTH - 60*rectScale(), appFont(15*rectScale(), NO));
        CGFloat imagHeight = 0;
        if (!isBlankString(self.listBO.pic)) {
            self.descLabel.frame = CGRectMake(30 * PLUS_SCALE, CGRectGetMaxY(self.imageV.frame) + 10 * PLUS_SCALE, SCREEN_WIDTH - 60 * PLUS_SCALE, sumHeight);
        } else {
            self.descLabel.frame = CGRectMake(30 * PLUS_SCALE, CGRectGetMaxY(self.titleLabel.frame) + 10 * PLUS_SCALE, SCREEN_WIDTH - 60 * PLUS_SCALE, sumHeight);
        }
    } else {
        self.descLabel.frame = CGRectMake(30 * PLUS_SCALE, CGRectGetMaxY(self.imageV.frame) + 10 * PLUS_SCALE, SCREEN_WIDTH - 60 * PLUS_SCALE, 0);
    }
}


Rendering after repair
Please add a picture description

Guess you like

Origin blog.csdn.net/LIUXIAOXIAOBO/article/details/131407070