Skip to content

Instantly share code, notes, and snippets.

View alongotv's full-sized avatar
💭
Hello everybody!

Vladimir alongotv

💭
Hello everybody!
  • Saint-Petersburg, RU
View GitHub Profile
@alongotv
alongotv / OnDidAppearSwiftUI
Last active February 10, 2023 17:21
Adds viewDidAppear callback to SwiftUI
struct ViewControllerLifecycleHandler: UIViewControllerRepresentable {
func makeCoordinator() -> ViewControllerLifecycleHandler.Coordinator {
Coordinator(onDidAppear: onDidAppear)
}
let onDidAppear: () -> Void
func makeUIViewController(context: UIViewControllerRepresentableContext<ViewControllerLifecycleHandler>) -> UIViewController {
context.coordinator
}
@alongotv
alongotv / UIImageFromGradient.swift
Created July 3, 2019 14:22
Function to generate an image consisting of a gradient between 2 colors
func imageWithGradient(startColor: UIColor, endColor: UIColor, size: CGSize, horizontally: Bool = true) -> UIImage? {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
gradientLayer.colors = [startColor.cgColor, endColor.cgColor]
if horizontally {
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
} else {
gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0)
@alongotv
alongotv / UrlParameters.swift
Last active August 30, 2022 07:29
Removes obsolete parameters from URL
/*
Usage:
let urlString = "https://example.com/?foo=bar&param2=none&__is_cowboy=false"
let url = URL(string: urlString)
let urlWithoutParameters = url?.removeParameters(with: ["param2", "__is_cowboy"])
print(urlWithoutParameters!)
Result: https://example.com/?foo=bar is printed
*/