TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | Custom |
ReleasedLast Release | Nov 2015 |
SPMSupports SPM | ✗ |
Maintained by Daniel Dahan.
Images come in all shapes and sizes. UIImage resize is a flexible way to resize images on the fly. The below example shows you how.
let p1: UIImage? = UIImage(named: "img1")
let p2: UIImage? = p1?.resize(toWidth: 300)
let p3: UIImage? = p1?.resize(toHeight: 200)
Crop images easily with UIImage crop. Below is an example:
let p1: UIImage? = UIImage(named: "img1")
let p2: UIImage? = p1?.crop(toWidth: 400, toHeight: 200)
Keep the moment by saving your images to Photo Library. Below is an example of cropping an image and saving it to the devices PhotoLibrary.
let p: UIImage? = UIImage(named: "img1")
p?.crop(toWidth: 400, toHeight: 200)?.writeToPhotoLibrary()
It is also possible to specify a target handler when saving to the Photo Library.
let p: UIImage? = UIImage(named: "img1")
p?.writeToPhotoLibrary(target: self)
Add the Photo Library save handler to the target object.
func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafePointer<Void>) {
let message: String = nil == error ? "Your photo has been saved!" : error!.localizedDescription
let a: UIAlertController = UIAlertController(title: "Status", message: message, preferredStyle: .Alert)
a.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(a, animated: true, completion: nil)
}
Not all images you may want to load will be available locally. No problem, use the UIImage class method contentsOfURL to load remote images asynchronously. Below is an example of its usage.
let url: NSURL = NSURL(string: "https://yourimage.io")!
UIImage.contentsOfURL(url) { (image: UIImage?, error: NSError?) in
if let v: UIImage = image {
// do something
}
}
Cycle through lines of text in any String. Below is an example of iterating through all lines of text in a String.
let text: String = "This is a\nblock of text\nthat has\nnewlines."
for line in text.lines {
print(line)
}
// output:
// This is a
// block of text
// that has
// newlines.
Remove the spaces and newlines from the beginning and end of a text block. Below is an example.
let text: String = " \n Hello World \n "
print(text.trim()) // output: Hello World
Get helpful directories.
print(File.applicationSupportDirectoryPath) // output: ../Application Support/
print(File.documentDirectoryPath) // output: ../Documents/
print(File.libraryDirectoryPath) // output: ../Library/
print(File.cachesDirectoryPath) // output: ../Library/Caches/
Easily create directories in different search paths.
let result: Bool = File.createDirectory("TestDirectory", inDirectory: .DocumentDirectory)
print(result) // output: true
As simple as it is to create a directory, it is to remove it.
let result: Bool = File.removeDirectory("TestDirectory", inDirectory: .DocumentDirectory)
print(result) // output: true