//
//  KNView.m
//  SmartCity
//
//  Created by Jason Lee on 1/27/16.
//  Copyright © 2016 ntels. All rights reserved.
//

#import "KNView.h"

@interface KNView () {
    BOOL _isNotFirstLoading;
}

@end

@implementation KNView

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    if (!_isNotFirstLoading) {
        _isNotFirstLoading = YES;
        
        for (NSLayoutConstraint *constraint in self.constraints) {
//            NSLog(@"%s\n %@", __PRETTY_FUNCTION__, constraint);
            
            if (constraint.firstAttribute == NSLayoutAttributeLeading || constraint.firstAttribute == NSLayoutAttributeTrailing) {
                
                if ([constraint.firstItem isEqual:self] || [constraint.secondItem isEqual:self]) {
                    CGFloat constant = constraint.constant;
                    
                    if (constraint.constant == 10.0f || constraint.constant == 12.0f || constraint.constant == 15.0f || constraint.constant == 27.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


@interface KNView2 () {
    BOOL _isNotFirstLoading;
}

@end

@implementation KNView2

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    if (!_isNotFirstLoading) {
        _isNotFirstLoading = YES;
        
        for (NSLayoutConstraint *constraint in self.constraints) {
//            NSLog(@"%s\n %@", __PRETTY_FUNCTION__, constraint);
            
            if (constraint.firstAttribute == NSLayoutAttributeLeading || constraint.firstAttribute == NSLayoutAttributeTrailing) {
                
                if ([constraint.firstItem isEqual:self] || [constraint.secondItem isEqual:self]) {
                    CGFloat constant = constraint.constant;
                    
                    if (constraint.constant == 10.0f || constraint.constant == 12.0f || constraint.constant == 15.0f || constraint.constant == 27.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
