Skip to content

Instantly share code, notes, and snippets.

View HarshilShah's full-sized avatar
🏎️

Harshil Shah HarshilShah

🏎️
View GitHub Profile
@HarshilShah
HarshilShah / UIFont+SmallCaps.swift
Last active September 4, 2022 22:06
A UIFont extension to use small caps San Francisco
//
// UIFont+SmallCaps.swift
//
// Created by Harshil Shah on 27/04/16.
// Copyright © 2016 Harshil Shah. All rights reserved.
//
import UIKit
extension UIFont {
@HarshilShah
HarshilShah / CollectionViewCellAnimation.swift
Last active March 7, 2022 21:14
UICollectionViewCell touch down animation
class CollectionViewCellAnimation: UICollectionViewCell {
override var isHighlighted: Bool {
didSet {
if isHighlighted {
handleTouchDown()
} else {
handleTouchUp()
}
}
@HarshilShah
HarshilShah / UIColor+Component.swift
Last active August 12, 2017 08:30
To simplify accessing UIColor components
//
// UIColor+Components.swift
//
// Created by Harshil Shah on 12/08/17.
// Copyright © 2017 Harshil Shah. All rights reserved.
//
import UIKit
extension UIColor {
@HarshilShah
HarshilShah / CIEdgePreserveUpsampleFilter.swift
Last active August 18, 2017 06:23
CIEdgePreserveUpsampleFilter usage
//
// CIEdgePreserveUpsampleFilter.swift
//
// Created by Harshil Shah on 18/08/17.
// Copyright © 2017 Harshil Shah. All rights reserved.
//
import CoreImage
extension CIImage {
@HarshilShah
HarshilShah / UIColor+DisplayP3Hue.swift
Created August 23, 2017 07:48
Initialise Display P3 UIColors using HSBA values
import UIKit
extension UIColor {
convenience init(displayP3Hue hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat = 1) {
// Bound colours to range of [0–1]
let newHue = max(0, min(1, hue))
let newSaturation = max(0, min(1, saturation))
let newBrightness = max(0, min(1, brightness))
@HarshilShah
HarshilShah / GrabberView.swift
Created September 14, 2017 07:33
Control Center-like grabber view
//
// GrabberView.swift
//
// Created by Harshil Shah on 23/07/17.
// Copyright © 2017 Harshil Shah. All rights reserved.
//
import UIKit
final class GrabberView: UIView {
@HarshilShah
HarshilShah / UIView+SafeAnchors.swift
Last active February 7, 2018 00:57
Fallbacks and syntactic sugar for iOS 11 safeArea API
//
// UIView+SafeAnchors.swift
//
extension UIView {
var safeTopAnchor: NSLayoutYAxisAnchor { return optionalSafeAreaLayoutGuide?.topAnchor ?? topAnchor }
var safeBottomAnchor: NSLayoutYAxisAnchor { return optionalSafeAreaLayoutGuide?.bottomAnchor ?? bottomAnchor }
var safeLeftAnchor: NSLayoutXAxisAnchor { return optionalSafeAreaLayoutGuide?.leftAnchor ?? leftAnchor }
@HarshilShah
HarshilShah / HSViewPropertyAnimator.swift
Created November 23, 2018 04:35
A UIViewPropertyAnimator subclass that adds a preparation phase
import UIKit
final class HSViewPropertyAnimator: UIViewPropertyAnimator {
private var preparations: [(UIViewAnimatingPosition) -> ()] = []
override func startAnimation() {
runPreparations()
super.startAnimation()
}
@HarshilShah
HarshilShah / keybase.md
Created September 12, 2019 09:30
Keybase

Keybase proof

I hereby claim:

  • I am harshilshah on github.
  • I am harshil (https://keybase.io/harshil) on keybase.
  • I have a public key ASDakFowAvIvGAamvulxzoszb7CcuYH4O0wpITZzq6Ojlwo

To claim this, I am signing this object:

@HarshilShah
HarshilShah / AsyncImage.swift
Created September 17, 2019 15:53
Generic asynchronous images in SwiftUI
protocol ImageLoader {
var image: UIImage? { get }
func fetchImage(forSize size: CGSize)
func cancelFetch()
}
struct AsyncImage<Loader: ObservableObject & ImageLoader>: View {
@ObservedObject var loader: Loader