Created
May 16, 2017 02:54
-
-
Save faimin/e640df6d29bce63c3fdbdc355f09f984 to your computer and use it in GitHub Desktop.
a UIView category for calculateDynamicHeight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (CGFloat)calculateDynamicHeightWithMaxWidth:(CGFloat)maxWidth { | |
| self.translatesAutoresizingMaskIntoConstraints = NO; | |
| CGFloat viewMaxWidth = maxWidth ? : CGRectGetWidth([UIScreen mainScreen].bounds); | |
| NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:viewMaxWidth]; | |
| [self addConstraint:widthConstraint]; | |
| CGSize fittingSize = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; | |
| [self removeConstraint:widthConstraint]; | |
| return fittingSize.height; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment