| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //
- // 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"
- #import "ImageUtil.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 = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:self.image];
- }
- return self;
- }
- - (void)awakeFromNib {//NIB로 로드될 경우,
- if (CGRectEqualToRect(_rectForCap, CGRectZero)) {
- self.image = [ImageUtil 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 = [ImageUtil 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 = [ImageUtil 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 = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:image];
- }
- [super setImage:sImage];
- }
- @end
|