//
//  KNTableViewCell.m
//  kneet2
//
//  Created by Jason Lee on 10/8/15.
//  Copyright © 2015 ntels. All rights reserved.
//

#import "KNTableViewCell.h"

@interface KNTableViewCell () {
    BOOL _isNotFirstLoading;
}

@end

@implementation KNTableViewCell

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    if (!self.superview) {
        return;
    }
    
    if (!_isNotFirstLoading) {
        _isNotFirstLoading = YES;
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        for (NSLayoutConstraint *constraint in self.contentView.constraints) {
            //        NSLog(@"%s\n %@", __PRETTY_FUNCTION__, constraint);
            
            
            if (constraint.firstAttribute == NSLayoutAttributeLeading || constraint.firstAttribute == NSLayoutAttributeTrailing) {
                
                if ([constraint.firstItem isEqual:self.contentView] || [constraint.secondItem isEqual:self.contentView]) {
                    CGFloat constant = constraint.constant;
                    
                    if (constraint.constant == 10.0f || constraint.constant == 12.0f || constraint.constant == 15.0f || constraint.constant == 27.0f || constraint.constant == 28.0f || constraint.constant == 30.0f) {
                        
                        if (IPHONE_WIDTH == 414.0f) {//아이폰 6p일 경우,
                            constant = constant + 20.0f;
                        } else if (IPHONE_WIDTH == 375.0f) {//아이폰 6일경우
                            constant = constant + 10.0f;
                        }
                    }
                    constraint.constant = constant;
                }
            }
        }
    }
}

@end


@interface KNTableViewCell2 () {
    BOOL _isNotFirstLoading;
}

@end


@implementation KNTableViewCell2

- (void)drawRect:(CGRect)rect {
//    [super drawRect:rect];
    
    if (!self.superview) {
        return;
    }
    
    // Initialization code
//    BOOL isHeader = [self isKindOfClass:[NSClassFromString(@"RulesConditionFooterTableViewCell") class]]; //for debug
    
    if (!_isNotFirstLoading) {
        _isNotFirstLoading = YES;
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        for (NSLayoutConstraint *constraint in self.contentView.constraints) {
            
            if (constraint.firstAttribute == NSLayoutAttributeLeading || constraint.firstAttribute == NSLayoutAttributeTrailing) {
                
                if ([constraint.firstItem isEqual:self.contentView] || [constraint.secondItem isEqual:self.contentView]) {
                    CGFloat constant = constraint.constant;
                    
                    if (constraint.constant == 10.0f || constraint.constant == 12.0f || constraint.constant == 15.0f || constraint.constant == 27.0f || constraint.constant == 28.0f || constraint.constant == 30.0f) {
                        
                        if (IPHONE_WIDTH == 414.0f) {//아이폰 6p일 경우,
                            constant = constant + 10.0f;
                        } else if (IPHONE_WIDTH == 375.0f) {//아이폰 6일경우
                            constant = constant + 5.0f;
                        }
                    }
                    constraint.constant = constant;
                }
            }
        }
    }
}

@end
