Skip to content

Instantly share code, notes, and snippets.

View adamgraham's full-sized avatar
🎨

Adam Graham adamgraham

🎨
View GitHub Profile
@adamgraham
adamgraham / UIColor+HSV.swift
Last active May 27, 2019 23:46
An extension of the iOS class UIColor to provide conversion to and from HSV (hue, saturation, value) colors.
/// An extension to provide conversion to and from HSV (hue, saturation, value) colors.
extension UIColor {
/// The HSV (hue, saturation, value) components of a color.
struct HSV: Hashable {
/// The hue component of the color, in the range [0, 360°].
var hue: CGFloat
/// The saturation component of the color, in the range [0, 100%].
var saturation: CGFloat
@adamgraham
adamgraham / UIColor+ARGB.swift
Last active May 27, 2019 23:26
An extension of the iOS class UIColor to provide conversion to and from ARGB (alpha, red, green, blue) colors.
/// An extension to provide conversion to and from ARGB (alpha, red, green, blue) colors.
extension UIColor {
/// The ARGB (alpha, red, green, blue) components of a color, in the range [0, 255].
struct ARGB: Hashable {
/// The alpha component of the color, in the range [0, 255].
var alpha: Int
/// The red component of the color, in the range [0, 255].
var red: Int
@adamgraham
adamgraham / UIColor+RGBA.swift
Last active May 27, 2019 23:27
An extension of the iOS class UIColor to provide conversion to and from RGBA (red, green, blue, alpha) colors.
/// An extension to provide conversion to and from RGBA (red, green, blue, alpha) colors.
extension UIColor {
/// The RGBA (red, green, blue, alpha) components of a color, in the range [0, 255].
struct RGBA: Hashable {
/// The red component of the color, in the range [0, 255].
var red: Int
/// The green component of the color, in the range [0, 255].
var green: Int
@adamgraham
adamgraham / DesignableBorder.swift
Last active May 18, 2019 03:13
An @IBDesignable extension of the iOS class UIView to provide customization of borders within Interface Builder.
protocol DesignableBorder {
var cornerRadius: CGFloat { get set }
var borderWidth: CGFloat { get set }
var borderColor: UIColor? { get set }
}
@IBDesignable extension UIView: DesignableBorder {
@adamgraham
adamgraham / DesignableShadow.swift
Last active May 18, 2019 03:13
An @IBDesignable extension of the iOS class UIView to provide customization of shadows within Interface Builder.
protocol DesignableShadow {
var shadowColor: UIColor? { get set }
var shadowOffset: CGSize { get set }
var shadowRadius: CGFloat { get set }
var shadowOpacity: Float { get set }
}
@IBDesignable extension UIView: DesignableShadow {
@adamgraham
adamgraham / String+CamelCase.swift
Last active July 30, 2023 12:56
An extension of the Swift String type to provide camel case formatting.
/// An extension to format strings in *camel case*.
extension String {
/// A collection of all the words in the string by separating out any punctuation and spaces.
var words: [String] {
return components(separatedBy: CharacterSet.alphanumerics.inverted).filter { !$0.isEmpty }
}
/// Returns a copy of the string with the first word beginning lowercased, and the first
/// letter of each word thereafter is capitalized, with no intervening spaces or punctuation,
@adamgraham
adamgraham / String+SnakeCase.swift
Last active May 18, 2019 03:13
An extension of the Swift String type to provide snake case formatting.
/// An extension to format strings in *snake case*.
extension String {
/// A collection of all the words in the string by separating out any punctuation and spaces.
var words: [String] {
return components(separatedBy: CharacterSet.alphanumerics.inverted).filter { !$0.isEmpty }
}
/// Returns a lowercased copy of the string with punctuation removed and spaces replaced
/// by a single underscore, e.g., "the_quick_brown_fox_jumps_over_the_lazy_dog".
@adamgraham
adamgraham / String+KebabCase.swift
Last active May 18, 2019 03:13
An extension of the Swift String type to provide kebab case formatting.
/// An extension to format strings in *kebab case*.
extension String {
/// A collection of all the words in the string by separating out any punctuation and spaces.
var words: [String] {
return components(separatedBy: CharacterSet.alphanumerics.inverted).filter { !$0.isEmpty }
}
/// Returns a lowercased copy of the string with punctuation removed and spaces replaced
/// by a single hyphen, e.g., "the-quick-brown-fox-jumps-over-the-lazy-dog".
@adamgraham
adamgraham / UIColor+CIExyY.swift
Last active June 2, 2019 00:22
An extension of the iOS class UIColor to provide conversion to and from CIE xyY colors.
/// An extension to provide conversion to and from CIE xyY colors.
extension UIColor {
/// The CIE xyY components of a color - luminance (Y) and chromaticity (x,y).
struct CIExyY: Hashable {
/// The x-axis chromaticity coordinate of the color, in the range [0, 1].
var x: CGFloat
/// The y-axis chromaticity coordinate of the color, in the range [0, 1].
var y: CGFloat
@adamgraham
adamgraham / UIColor+HunterLab.swift
Last active June 2, 2019 03:54
An extension of the iOS class UIColor to provide conversion to and from Hunter Lab colors.
/// An extension to provide conversion to and from Hunter Lab colors.
extension UIColor {
/// XYZ tristimulus values of d65 illuminant with standard 2° observer.
private static let d65: (X: CGFloat, Y: CGFloat, Z: CGFloat) = (95.047, 100.000, 108.883)
/// The Hunter Lab components of a color - lightness (L) and chromaticity (a,b).
struct HunterLab: Hashable {
/// The lightness component of the color, in the range [0, 100] (darkest to brightest).