CustomImageView.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // CustomImageView.m
  3. // JasonDevelop
  4. //
  5. // Created by Jason Lee on 10/25/14.
  6. // Copyright (c) jasondevelop. All rights reserved.
  7. //
  8. #import "UIView+AutoLayoutDebugging.h"
  9. #import "CommonUtil.h"
  10. #import "CustomImageView.h"
  11. #import "ImageUtil.h"
  12. @implementation CustomImageView
  13. #define kfRoundWidth 4.0f
  14. - (id)initWithImage:(UIImage *)image rectForCap:(CGRect)rectForCap {
  15. if (self = [super initWithImage:image]) {
  16. _rectForCap = rectForCap;
  17. CGFloat top, left, bottom, right;
  18. top = CGRectGetMinY(_rectForCap);
  19. left = CGRectGetMinX(_rectForCap);
  20. bottom = CGRectGetHeight(_rectForCap);
  21. right = CGRectGetWidth(_rectForCap);
  22. self.image = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:self.image];
  23. }
  24. return self;
  25. }
  26. - (void)awakeFromNib {//NIB로 로드될 경우,
  27. if (CGRectEqualToRect(_rectForCap, CGRectZero)) {
  28. self.image = self.image;
  29. } else {
  30. CGFloat top, left, bottom, right;
  31. top = CGRectGetMinY(_rectForCap);
  32. left = CGRectGetMinX(_rectForCap);
  33. bottom = CGRectGetHeight(_rectForCap);
  34. right = CGRectGetWidth(_rectForCap);
  35. self.image = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:self.image];
  36. }
  37. #ifdef DEBUG
  38. NSString *identifier = [NSString stringWithFormat:@"CustomImage:(%@)", NSStringFromCGRect(self.frame)];
  39. [self setValue:identifier forKey:@"layoutDebuggingIdentifier"];
  40. #endif
  41. }
  42. - (void)setImage:(UIImage *)image {
  43. UIImage *sImage = nil;
  44. if (!CGRectEqualToRect(_rectForCap, CGRectZero)) {
  45. sImage = image;
  46. } else {
  47. CGFloat top, left, bottom, right;
  48. top = CGRectGetMinY(_rectForCap);
  49. left = CGRectGetMinX(_rectForCap);
  50. bottom = CGRectGetHeight(_rectForCap);
  51. right = CGRectGetWidth(_rectForCap);
  52. sImage = [ImageUtil resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch img:image];
  53. }
  54. [super setImage:sImage];
  55. }
  56. @end