This file contains hidden or 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 | |
class QuadPageControl: UIPageControl { | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
guard !subviews.isEmpty else { return } | |
let spacing: CGFloat = 3 | |
This file contains hidden or 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 UIImage { | |
static func imageFromView(view: UIView) -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0) | |
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} |
This file contains hidden or 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 UIImage { | |
static func placeholder(size: CGSize) -> UIImage { | |
UIGraphicsBeginImageContext(size) | |
let context = UIGraphicsGetCurrentContext() | |
CGContextSetRGBFillColor(context, 0, 0, 0, 1) | |
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height)) | |
This file contains hidden or 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 | |
class CustomURLCache: NSURLCache { | |
let createdAtKey = "CreatedAt" | |
override func cachedResponseForRequest(request:NSURLRequest) -> NSCachedURLResponse? { | |
let cachedResponse = expiredCachedResponseForRequest(request) | |
if cachedResponse == nil { |
This file contains hidden or 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 | |
extension String { | |
var titleizedString: String { | |
return String(characters.prefix(1)).uppercaseString + String(characters.dropFirst()) | |
} | |
} |
This file contains hidden or 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 UIViewController { | |
func presentAlert(message: String) { | |
if presentedViewController == nil { | |
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .Alert) | |
let alertAction = UIAlertAction(title: "OK", style: .Default, handler: nil) | |
alertController.addAction(alertAction) | |
This file contains hidden or 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 SpriteKit | |
extension SKNode { | |
public func removeChildrenWithName(name: String) { | |
enumerateChildNodesWithName(name) { (node, stop) -> Void in | |
node.removeFromParent() | |
} | |
} | |
} |
This file contains hidden or 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 | |
func degreesToRadians(degrees: CGFloat) -> CGFloat { | |
return degrees * CGFloat(M_PI) / 180 | |
} | |
func radiansToDegress(radians: CGFloat) -> CGFloat { | |
return radians * 180 / CGFloat(M_PI) | |
} |
This file contains hidden or 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 CGSize { | |
public init(side: CGFloat) { | |
width = side | |
height = side | |
} | |
public init(side: Double) { | |
width = CGFloat(side) |