// // CustomImageView.m // JasonDevelop // // Created by Jason Lee on 10/25/14. // Copyright (c) jasondevelop. All rights reserved. // #import "UIView+AutoLayoutDebugging.h" #import "CommonUtil.h" #import "CustomImageView.h" @implementation CustomImageView #define kfRoundWidth 4.0f - (id)initWithImage:(UIImage *)image rectForCap:(CGRect)rectForCap { if (self = [super initWithImage:image]) { _rectForCap = rectForCap; CGFloat top, left, bottom, right; top = CGRectGetMinY(_rectForCap); left = CGRectGetMinX(_rectForCap); bottom = CGRectGetHeight(_rectForCap); right = CGRectGetWidth(_rectForCap); self.image = [CommonUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:self.image]; } return self; } - (void)awakeFromNib {//NIB로 로드될 경우, if (CGRectEqualToRect(_rectForCap, CGRectZero)) { self.image = [CommonUtil resizableImageWithCapInsets:UIEdgeInsetsMake(kfRoundWidth, kfRoundWidth, kfRoundWidth, kfRoundWidth) resizingMode:UIImageResizingModeStretch img:self.image]; } else { if (!CGRectEqualToRect(_rectForCap, CGRectMake(-1, 0, 0, 0))) { CGFloat top, left, bottom, right; top = CGRectGetMinY(_rectForCap); left = CGRectGetMinX(_rectForCap); bottom = CGRectGetHeight(_rectForCap); right = CGRectGetWidth(_rectForCap); self.image = [CommonUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:self.image]; } } #ifdef DEBUG NSString *identifier = [NSString stringWithFormat:@"CustomImage:(%@)", NSStringFromCGRect(self.frame)]; [self setValue:identifier forKey:@"layoutDebuggingIdentifier"]; #endif } - (void)setImage:(UIImage *)image { UIImage *sImage = nil; if (CGRectEqualToRect(_rectForCap, CGRectZero)) { sImage = [CommonUtil resizableImageWithCapInsets:UIEdgeInsetsMake(kfRoundWidth, kfRoundWidth, kfRoundWidth, kfRoundWidth) resizingMode:UIImageResizingModeStretch img:image]; } else { CGFloat top, left, bottom, right; top = CGRectGetMinY(_rectForCap); left = CGRectGetMinX(_rectForCap); bottom = CGRectGetHeight(_rectForCap); right = CGRectGetWidth(_rectForCap); sImage = [CommonUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:image]; } [super setImage:sImage]; } @end