Skip to content

Instantly share code, notes, and snippets.

View CrystDragon's full-sized avatar

Lincoln Wu CrystDragon

View GitHub Profile
@CrystDragon
CrystDragon / TestViewProperties.swift
Last active August 22, 2018 06:34
Test relations between main properties of `UIView`
import UIKit
extension UIView {
func dumpProperties() {
print("""
- bounds: \(bounds)
- frame: \(frame)
- center: \(center)
@CrystDragon
CrystDragon / Sequence+max.swift
Created June 20, 2019 09:33
A type-erased keyPath-based multi-argument max helper
/// library
/// a type-erased interface
private final class ComparatorHolder<S: Sequence> {
private typealias Comparator = (S.Element, S.Element) -> Int
private let base: S
private var comparators: [Comparator] = []
@CrystDragon
CrystDragon / ExploreSRGB.swift
Last active October 24, 2022 15:03
Explore gamma correction related properties on iOS
// test in playground targeting iOS
import UIKit
import QuartzCore
let sRGBSpace = CGColorSpace(name: CGColorSpace.sRGB)!
let linearSpace = CGColorSpace(name: CGColorSpace.linearSRGB)!
func dumpImageFirstPixel(_ image: UIImage) {
guard let cgImage = image.cgImage,
let dataBuffer = cgImage.dataProvider?.data as Data?,
@CrystDragon
CrystDragon / MyTextLabel.swift
Created May 17, 2018 08:19
Most basic custom UITextInput conformance, without selection interaction, no UI elements but only pure texts.
import UIKit
class MyTextLabel: UIView {
var textLayer = CATextLayer()
var textStorage: String = "" {
didSet {
textLayer.string = textStorage
}
}