gsdios / SDAutoLayout

One line of code to implement automatic layout. 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库。The most easy way for autoLayout. Based on runtime.
MIT License
5.9k stars 1.28k forks source link

ios12 UIButton布局死循环问题 #285

Open libingting opened 6 years ago

libingting commented 6 years ago

给button设置了约束满足MaxWidth与autoHeightRatio即在源码中 view.autoHeightRatioValue && view.width_sd > 0生效下执行 [self layoutAutoHeightWidthView:view model:model];

//在ios12中的layoutSubviews函数中执行“label.numberOfLines = 0”会造成死循环,ios11没有这个问题 label.numberOfLines = 0;

//在ios12中的layoutSubviews函数中执行“label.numberOfLines = 0”会造成死循环,ios11没有这个问题

        label.numberOfLines = 0;

        if (label.text.length) {
            if (!label.isAttributedContent) {
                CGRect rect = [label.text boundingRectWithSize:CGSizeMake(label.width_sd, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : label.font} context:nil];
                label.height_sd = rect.size.height + 0.1;
            } else {
                [label sizeToFit];
                if (label.sd_maxWidth && label.width_sd > [label.sd_maxWidth floatValue]) {
                    label.width_sd = [label.sd_maxWidth floatValue];
                }
            }
        } else {
            label.height_sd = 0;
        }
    } else {
        view.height_sd = 0;
    }
}

}