SHARE
TWEET

fix the wrong value of sizeThatFits in a UITableViewCell

priore Sep 11th, 2014 652 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //  fix the wrong value of sizeThatFits in a UITableViewCell for iOS8
  2. //  UITableViewCell+iOS8.h
  3. #import <UIKit/UIKit.h>
  4.  
  5. @interface UITableViewCell (iOS8)
  6.  
  7. - (CGSize)sizeThatFitsiOS8:(CGSize)size;
  8.  
  9. @end
  10.  
  11. //  UITableViewCell+iOS8.m
  12. #import "UITableViewCell+iOS8.h"
  13.  
  14. @implementation UITableViewCell (iOS8)
  15.  
  16. - (CGSize)sizeThatFitsiOS8:(CGSize)size
  17. {
  18.         if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) {
  19.  
  20.                         @try {
  21.                         [self setNeedsLayout];
  22.                         [self layoutIfNeeded];
  23.                         }
  24.                         @catch (NSException *exception) {}
  25.        
  26.                         CGSize new_size = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
  27.                         return new_size;
  28.        
  29.     }
  30.    
  31.     return [self sizeThatFits:size];
  32. }
  33.  
  34. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top