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
- (nullable UIImage *)sampleImage { | |
CGRect bounds = CGRectMake(0, 0, 50, 50); | |
UIColor *color = [UIColor colorWithDisplayP3Red:1 green:0.5 blue:0.25 alpha:1]; | |
UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0); | |
[color setFill]; | |
UIRectFill(bounds); | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
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
import Foundation | |
import CoreImage | |
/** | |
Based on: https://gist.github.com/SheffieldKevin/566dc048dd6f36716bcd | |
Updated for Swift 5.5 (Xcode 13) | |
*/ | |
class ImageDiff { | |
func compare(leftImage: CGImage, rightImage: CGImage) throws -> Int { |
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
import UIKit | |
import MobileCoreServices // needed for kUTTypeGIF | |
extension Array where Element == UIImage { | |
/** | |
Writes a looping animated gif to the documents folder, using the receiver's elements as the frames. | |
Based on [this answer](https://stackoverflow.com/a/46095888/433373) from Stack Overflow. | |
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
import UIKit | |
extension UIBezierPath { | |
/** | |
Draws the super-elliptic analog of a rounded rect. Unlike the regular rounded rect, the rounded corners | |
are the quadrants of a superellipse (i.e., parabolic segments), _not_ circular arcs. | |
If `rect` is a square and `cornerRadius` is equal to half the length or more, and actual superellipse is | |
drawn (no straight sections along its boundary) just like doing the same with a rounded rect results in a | |
circle being drawn. |
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
import CoreGraphics | |
extension CGFloat { | |
/// See this: https://tauday.com/tau-manifesto | |
static var tau: CGFloat { | |
return 2 * CGFloat.pi | |
} | |
} |
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
/** | |
Provides convenient shorthands for initializing `NSError` objects. | |
*/ | |
extension NSError { | |
/** | |
Same as `init(domain:code:userInfo:)`, but `domain` defaults to the app's | |
bundle indentifier. | |
*/ | |
convenience init(code: Int, userInfo: [NSObject : AnyObject]?) { | |
let bundleIdentifier = NSBundle.mainBundle().bundleIdentifier! |
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
extension UIImage { | |
/** | |
Calculates the resulting size (rendered on screen) of the receiver when it | |
is displayed within a `UIImageView` instance of bounds size `containerSize` | |
that has its `contentMode` property set to `.ScaleAspectFit`. | |
- parameter contanerSize: The size of the hypothetical UIImageView instance | |
that is to display the receiver on screen. | |
- returns: the effective size at which the receiver would be rendered on | |
screen if displayed in said view. |
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
import UIKit | |
extension UIColor { | |
convenience init( | |
redByte red: UInt8, | |
greenByte green: UInt8, | |
blueByte blue: UInt8, | |
alphaByte alpha: UInt8 | |
) { | |
self.init( |
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
- (CGFloat) imageScaleFactorFromFilename:(NSString*) imageFileName | |
{ | |
NSString* filename = [imageFileName stringByDeletingPathExtension]; | |
NSArray* components = [filename componentsSeparatedByString:@"@"]; | |
if ([components count] > 1) { | |
// Hi res image | |
NSString* scaleSubstring = [components objectAtIndex:1]; // e.g. @"2x" |
NewerOlder