Skip to content

Instantly share code, notes, and snippets.

@priore
Created November 12, 2014 11:21
Show Gist options
  • Save priore/9c24dad864c70ebccfc3 to your computer and use it in GitHub Desktop.
Save priore/9c24dad864c70ebccfc3 to your computer and use it in GitHub Desktop.
fix the wrong value of sizeThatFits in a UITableViewCell
// fix the wrong value of sizeThatFits in a UITableViewCell for iOS8
// UITableViewCell+iOS8.h
#import <UIKit/UIKit.h>
@interface UITableViewCell (iOS8)
- (CGSize)sizeThatFitsiOS8:(CGSize)size;
@end
// UITableViewCell+iOS8.m
#import "UITableViewCell+iOS8.h"
@implementation UITableViewCell (iOS8)
- (CGSize)sizeThatFitsiOS8:(CGSize)size
{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) {
@try {
[self setNeedsLayout];
[self layoutIfNeeded];
}
@catch (NSException *exception) {}
CGSize new_size = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return new_size;
}
return [self sizeThatFits:size];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment