Skip to content

Instantly share code, notes, and snippets.

Lincoln Wu CrystDragon

Block or report user

Report or block CrystDragon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@CrystDragon
CrystDragon / MyTextLabel.swift
Created May 17, 2018
Most basic custom UITextInput conformance, without selection interaction, no UI elements but only pure texts.
View MyTextLabel.swift
import UIKit
class MyTextLabel: UIView {
var textLayer = CATextLayer()
var textStorage: String = "" {
didSet {
textLayer.string = textStorage
}
}
@CrystDragon
CrystDragon / Sequence+max.swift
Created Jun 20, 2019
A type-erased keyPath-based multi-argument max helper
View Sequence+max.swift
/// 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 / TestViewProperties.swift
Last active Aug 22, 2018
Test relations between main properties of `UIView`
View TestViewProperties.swift
import UIKit
extension UIView {
func dumpProperties() {
print("""
- bounds: \(bounds)
- frame: \(frame)
- center: \(center)
@CrystDragon
CrystDragon / ExploreSRGB.swift
Last active Jul 11, 2018
Explore gamma correction related properties on iOS
View ExploreSRGB.swift
// 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?,
You can’t perform that action at this time.