Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 1.0.0
Fetching contributors…

Cannot retrieve contributors at this time

file 53 lines (39 sloc) 1.573 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
//
// UIImage+SSToolkitAdditions.m
// SSToolkit
//
// Created by Sam Soffes on 11/17/09.
// Copyright 2009-2011 Sam Soffes. All rights reserved.
//

#import "UIImage+SSToolkitAdditions.h"

@implementation UIImage (SSToolkitAdditions)

+ (UIImage *)imageNamed:(NSString *)imageName bundleName:(NSString *)bundleName {
if (!bundleName) {
return [UIImage imageNamed:imageName];
}

NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *bundlePath = [resourcePath stringByAppendingPathComponent:bundleName];
NSString *imagePath = [bundlePath stringByAppendingPathComponent:imageName];
return [UIImage imageWithContentsOfFile:imagePath];
}


- (UIImage *)imageCroppedToRect:(CGRect)rect {
// CGImageCreateWithImageInRect's `rect` parameter is in pixels of the image's coordinates system. Convert from points.
CGFloat scale = self.scale;
rect = CGRectMake(rect.origin.x * scale, rect.origin.y * scale, rect.size.width * scale, rect.size.height * scale);

CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}


- (UIImage *)squareImage {
CGSize imageSize = self.size;
CGFloat shortestSide = fminf(imageSize.width, imageSize.height);
return [self imageCroppedToRect:CGRectMake(0.0f, 0.0f, shortestSide, shortestSide)];
}


- (NSInteger)rightCapWidth {
return (NSInteger)self.size.width - (self.leftCapWidth + 1);
}


- (NSInteger)bottomCapHeight {
return (NSInteger)self.size.height - (self.topCapHeight + 1);
}

@end
Something went wrong with that request. Please try again.