priore

fix the wrong value of sizeThatFits in a UITableViewCell

Sep 11th, 2014
835
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×