Skip to content

Instantly share code, notes, and snippets.

View CodingMeSwiftly's full-sized avatar

Max Kraus CodingMeSwiftly

View GitHub Profile
@CodingMeSwiftly
CodingMeSwiftly / CAMediaTimingFunction+UITimingCurveProvider.swift
Last active August 10, 2019 10:43
An extension on CAMediaTimingFunction to enable interoperability with UIViewProtertyAnimator
import UIKit
import QuartzCore
//MARK: - NSCopying
extension CAMediaTimingFunction: NSCopying {
public func copy(with zone: NSZone? = nil) -> Any {
let c1 = controlPoint1
let c2 = controlPoint2
return CAMediaTimingFunction(controlPoints: Float(c1.x), Float(c1.y), Float(c2.x), Float(c2.y))
@CodingMeSwiftly
CodingMeSwiftly / UIView+AnimationContext.swift
Created August 10, 2019 10:38
An extension on UIView to retrieve information about the animation context the view is currently in.
import UIKit
extension UIView {
struct AnimationContext {
public let duration: TimeInterval
public let timingParameters: UITimingCurveProvider?
}
}
extension UIView {
@CodingMeSwiftly
CodingMeSwiftly / UIScrollView+CanScroll.swift
Created November 12, 2017 21:30
An extension on UIScrollView that adds vars to check if the scroll view can scroll.
extension UIEdgeInsets {
var horizontalSum: CGFloat {
return left + right
}
var verticalSum: CGFloat {
return top + bottom
}
}
@CodingMeSwiftly
CodingMeSwiftly / UIImage+TintColor.swift
Last active November 7, 2017 17:20
Shows how to apply alpha masked tintColor to a UIImage in Swift 4.
import UIKit
extension UIImage {
func tinted(with tintColor: UIColor) -> UIImage {
guard let cgImage = cgImage else { return self }
UIGraphicsBeginImageContextWithOptions(size, false, scale)
defer { UIGraphicsEndImageContext() }
guard let context = UIGraphicsGetCurrentContext() else { return self }