-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageResizeToMax.codesnippet
More file actions
38 lines (36 loc) · 1.47 KB
/
imageResizeToMax.codesnippet
File metadata and controls
38 lines (36 loc) · 1.47 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>image_resize_to_max</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>ClassImplementation</string>
</array>
<key>IDECodeSnippetContents</key>
<string>- (UIImage *)resizeImage:(UIImage *)image toMaximumSize:(CGSize)maxSize {
CGFloat widthRatio = maxSize.width / image.size.width;
CGFloat heightRatio = maxSize.height / image.size.height;
CGFloat scaleRatio = widthRatio < heightRatio ? widthRatio : heightRatio;
CGSize newSize = CGSizeMake(image.size.width * scaleRatio, image.size.height * scaleRatio);
UIGraphicsBeginImageContextWithOptions(newSize, NO, image.scale);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resizedImage;
}</string>
<key>IDECodeSnippetIdentifier</key>
<string>E059CA93-2052-458B-AAFD-D98DD539954C</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Objective-C</string>
<key>IDECodeSnippetSummary</key>
<string>image_resize_to_max</string>
<key>IDECodeSnippetTitle</key>
<string>Image Resize to Max</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>