Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (39 sloc) 1.573 kb
e308774 @soffes Added categories and fixed bug in connection
soffes authored
1 //
f3d43b6 @soffes The Great Rename
soffes authored
2 // UIImage+SSToolkitAdditions.m
3 // SSToolkit
e308774 @soffes Added categories and fixed bug in connection
soffes authored
4 //
1cdef2a @soffes Cleaned up categories
soffes authored
5 // Created by Sam Soffes on 11/17/09.
e8c3ce3 @soffes Updated comments and renamed SSDrawingMacros to SSDrawingUtilities
soffes authored
6 // Copyright 2009-2011 Sam Soffes. All rights reserved.
e308774 @soffes Added categories and fixed bug in connection
soffes authored
7 //
8
f3d43b6 @soffes The Great Rename
soffes authored
9 #import "UIImage+SSToolkitAdditions.h"
1cdef2a @soffes Cleaned up categories
soffes authored
10
f3d43b6 @soffes The Great Rename
soffes authored
11 @implementation UIImage (SSToolkitAdditions)
1cdef2a @soffes Cleaned up categories
soffes authored
12
072f882 @soffes More documentation. #24 #25
soffes authored
13 + (UIImage *)imageNamed:(NSString *)imageName bundleName:(NSString *)bundleName {
14 if (!bundleName) {
15 return [UIImage imageNamed:imageName];
16 }
17
1cdef2a @soffes Cleaned up categories
soffes authored
18 NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
19 NSString *bundlePath = [resourcePath stringByAppendingPathComponent:bundleName];
20 NSString *imagePath = [bundlePath stringByAppendingPathComponent:imageName];
21 return [UIImage imageWithContentsOfFile:imagePath];
22 }
e308774 @soffes Added categories and fixed bug in connection
soffes authored
23
24
36b49e0 @soffes Added squaredImage to UIImage
soffes authored
25 - (UIImage *)imageCroppedToRect:(CGRect)rect {
9beaa2a @soffes Fixed typeo in UIImage category
soffes authored
26 // CGImageCreateWithImageInRect's `rect` parameter is in pixels of the image's coordinates system. Convert from points.
f63bf11 @soffes More documentation
soffes authored
27 CGFloat scale = self.scale;
9beaa2a @soffes Fixed typeo in UIImage category
soffes authored
28 rect = CGRectMake(rect.origin.x * scale, rect.origin.y * scale, rect.size.width * scale, rect.size.height * scale);
f63bf11 @soffes More documentation
soffes authored
29
9beaa2a @soffes Fixed typeo in UIImage category
soffes authored
30 CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect);
e308774 @soffes Added categories and fixed bug in connection
soffes authored
31 UIImage *cropped = [UIImage imageWithCGImage:imageRef];
32 CGImageRelease(imageRef);
072f882 @soffes More documentation. #24 #25
soffes authored
33 return cropped;
e308774 @soffes Added categories and fixed bug in connection
soffes authored
34 }
35
36b49e0 @soffes Added squaredImage to UIImage
soffes authored
36
37 - (UIImage *)squareImage {
f63bf11 @soffes More documentation
soffes authored
38 CGSize imageSize = self.size;
39 CGFloat shortestSide = fminf(imageSize.width, imageSize.height);
f643aac @soffes Switched to LLVM 1.6 and enabled additional warnings. Updated code to co...
soffes authored
40 return [self imageCroppedToRect:CGRectMake(0.0f, 0.0f, shortestSide, shortestSide)];
36b49e0 @soffes Added squaredImage to UIImage
soffes authored
41 }
42
b645210 @soffes Use rightCapWidth when calculating segmented control sizes instead of as...
soffes authored
43
44 - (NSInteger)rightCapWidth {
81498ef @soffes Fixed sign issues
soffes authored
45 return (NSInteger)self.size.width - (self.leftCapWidth + 1);
b645210 @soffes Use rightCapWidth when calculating segmented control sizes instead of as...
soffes authored
46 }
47
072f882 @soffes More documentation. #24 #25
soffes authored
48
49 - (NSInteger)bottomCapHeight {
50 return (NSInteger)self.size.height - (self.topCapHeight + 1);
51 }
52
e308774 @soffes Added categories and fixed bug in connection
soffes authored
53 @end
Something went wrong with that request. Please try again.