随笔 - 112  文章 - 0  评论 - 9  阅读 - 13万

IOS--通过宽度算高度

复制代码
//通过宽度算高度
- (CGFloat)sugguestHeightForWidth:(CGFloat)width
{
    NSLayoutConstraint *tempWidthConstraint =
    [NSLayoutConstraint constraintWithItem:self
                                 attribute:NSLayoutAttributeWidth
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:nil
                                 attribute:NSLayoutAttributeNotAnAttribute
                                multiplier:1.0
                                  constant:width];
    [self addConstraint:tempWidthConstraint];
    CGSize fittingSize = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    [self removeConstraint:tempWidthConstraint];
    return fittingSize.height;
}
复制代码
1 CGFloat height = [addShelfView sugguestHeightForWidth:self.view.hm_width];
2         addShelfView.hm_height = height;

 

posted on   麦芽呀~  阅读(460)  评论(0编辑  收藏  举报
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示