Advertisement
undeadhip

Untitled

Apr 13th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. + (void)reloadTableHeaderOrFooterViewWithDynamicHeight:(UIView *)view width:(CGFloat)width {
  2.     NSParameterAssert(width);
  3.     NSParameterAssert(view);
  4.    
  5.     view.frame = CGRectMake(0, 0, width, 10000);
  6.     view.translatesAutoresizingMaskIntoConstraints = NO;
  7.  
  8.     NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:width];
  9.     constraint.active = YES;
  10.  
  11.     [view setNeedsLayout];
  12.     [view layoutIfNeeded];
  13.  
  14.     CGFloat height = [view systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  15.  
  16.     constraint.active = NO;
  17.  
  18.     //update the header's frame and set it again
  19.     CGRect headerFrame = view.frame;
  20.     headerFrame.size.height = height;
  21.     headerFrame.size.width = width;
  22.     view.frame = headerFrame;
  23.  
  24.     view.translatesAutoresizingMaskIntoConstraints = YES;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement