Objective-C Tips & Trick - Prioregroup.com
[Objective-C] fix the wrong value of sizeThatFits in a UITableViewCell
       
back

//  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






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com