-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
playgrounds/extensions/UIImage+crop.playground/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import UIKit | ||
|
||
var str = "Hello, playground" | ||
|
||
extension UIImage { | ||
// add a crop function to UIImage | ||
func crop(to: CGRect) -> UIImage? { | ||
switch (self.cgImage, self.ciImage) { | ||
// check if cgImage is some, ciImage is nil and unwrap self.cgImage, storing it in cgImage | ||
case (.some(let cgImage), nil): | ||
let image = cgImage.cropping(to: to) | ||
return image.map { UIImage(cgImage: $0) } | ||
case (nil, .some(let ciImage)): | ||
return UIImage(ciImage: ciImage.cropped(to: to)) | ||
default: | ||
print("I don't know why cgImage and ciImage are equal") | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
var image: UIImage = UIImage() // assume set elsewhere | ||
let croppedImage = image.crop(to: CGRect(x: 0.0, y: 0.0, width: 25.0, height: 25.0)) |
4 changes: 4 additions & 0 deletions
4
playgrounds/extensions/UIImage+crop.playground/contents.xcplayground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' executeOnSourceChanges='false'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
...rounds/extensions/UIImage+crop.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...ions/UIImage+crop.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |