Skip to content

Instantly share code, notes, and snippets.

@advantis
Created June 12, 2013 14:08
Show Gist options
  • Save advantis/5765588 to your computer and use it in GitHub Desktop.
Save advantis/5765588 to your computer and use it in GitHub Desktop.
Creating casual resizable image
//
// Copyright © 2013 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface UIImage (ADVImageResizing)
- (UIImage *) resizableImage;
@end
//
// Copyright © 2013 Yuri Kotov
//
#import "UIImage+ADVImageResizing.h"
#import <tgmath.h>
NS_INLINE UIEdgeInsets InsetsForSize(CGSize size)
{
CGFloat top = floor(size.height / 2.f);
CGFloat left = floor(size.width / 2.f);
return UIEdgeInsetsMake(top, left, top - 1.f, left - 1.f);
}
@implementation UIImage (ADVImageResizing)
- (UIImage *) resizableImage
{
return [self resizableImageWithCapInsets:InsetsForSize(self.size)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment