Skip to content

Instantly share code, notes, and snippets.

View RomanEsin's full-sized avatar
🎯
Focusing

Roman Esin RomanEsin

🎯
Focusing
View GitHub Profile
@RomanEsin
RomanEsin / ControllerAnimatable.swift
Last active June 28, 2020 09:34
Animate Game Controller light. This little code snippet will allow you to animate the light of the controller when using GameController API.
import Foundation
import GameController
protocol ControllerAnimatable: class {
var controller: GCController { get }
}
extension ControllerAnimatable {
/// Animates controller light color to a specified color of `GCColor` type.
/// - Parameters:
@RomanEsin
RomanEsin / replaceColor.swift
Last active October 20, 2022 19:35 — forked from andrey-str/replaceColor.swift
Replace color in UIImage with give tolerance value
// color - source color, which is must be replaced
// withColor - target color
// tolerance - value in range from 0 to 1
func replaceColor(color: UIColor, withColor: UIColor, image: UIImage, tolerance: CGFloat) -> UIImage {
// This function expects to get source color(color which is supposed to be replaced)
// and target color in RGBA color space, hence we expect to get 4 color components: r, g, b, a
assert(color.cgColor.numberOfComponents == 4 && withColor.cgColor.numberOfComponents == 4,
"Must be RGBA colorspace")
@RomanEsin
RomanEsin / SwiftUI Dark Preview
Created January 1, 2021 06:55
A simple extension to quickly preview dark theme of your view in SwiftUI previews.
// In your preview struct just add
// `darkThemePreview()` to the view you're previewing!
import SwiftUI
extension View {
func darkThemePreview() -> some View {
Group {
self
self