Skip to content

Instantly share code, notes, and snippets.

View Codelaby's full-sized avatar

Codelaby Codelaby

View GitHub Profile
//
// ContentView.swift
// AnimationTimingCurve
//
// Created by Chris Eidhof on 25.09.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
@Codelaby
Codelaby / view_snapshot.swift
Created March 19, 2025 08:35
snapshot View to image in swift
/// Renders `View` as `UIImage`.
extension View {
func snapshot(renderOnce: UnsafeMutablePointer<Bool>? = nil) -> UIImage? {
if let flag = renderOnce, flag.pointee {
return nil
}
renderOnce?.pointee = true
let renderer = ImageRenderer(content: self)
renderer.scale = UIScreen.main.scale
@Codelaby
Codelaby / ReorderableListExample.swift
Created March 17, 2025 09:26 — forked from JEuler/ReorderableListExample.swift
SwiftUI Reorder With Buttons List Example
import SwiftUI
// Simple example of a custom reordering implementation in SwiftUI
struct ReorderableListExample: View {
// Sample data
@State private var items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
@State private var isEditMode: EditMode = .inactive
var body: some View {
VStack {
@Codelaby
Codelaby / FloatingOverlayApp.swift
Created March 15, 2025 08:38 — forked from JuniperPhoton/FloatingOverlayApp.swift
A simple application to show a black, resizable, title-less, always-on-top NSWindow on Mac.
//
// FloatingOverlayApp.swift
// FloatingOverlay
//
// Created by JuniperPhoton on 2025/3/12.
//
import SwiftUI
// Dependency: https://github.com/sindresorhus/KeyboardShortcuts
@Codelaby
Codelaby / gradient_sunburst.swift
Created March 14, 2025 18:12
Sunburst in SwiftUI
class Stripes {
static func stripedAngularGradient(
_ colors: [Color],
stripeCount: Int = 2,
center: UnitPoint = .center,
angle: Angle = .zero
) -> AngularGradient {
let stripeWidth: CGFloat = 1.0 / CGFloat(stripeCount)
@Codelaby
Codelaby / Shimmer.swift
Created March 6, 2025 07:53 — forked from xavierLowmiller/Shimmer.swift
Slide-to-Unlock animation in SwiftUI
import SwiftUI
public struct Shimmer: AnimatableModifier {
private let gradient: Gradient
@State private var position: CGFloat = 0
public var animatableData: CGFloat {
get { position }
@Codelaby
Codelaby / AppearancePicker.swift
Created March 5, 2025 10:13
Apperance Picker, Theme switch for swiftUI
struct AppearancePicker<SelectionValue, Content>: View where SelectionValue: Hashable & Sendable, Content: View {
private var items: [SelectionValue]
@Binding var selection: SelectionValue
let content: (SelectionValue) -> Content
// Public initializer
init(items: [SelectionValue], selection: Binding<SelectionValue>, @ViewBuilder content: @escaping (SelectionValue) -> Content) {
self.items = items
self._selection = selection
self.content = content
@Codelaby
Codelaby / AppleBookScrollDemo.swift
Last active February 26, 2025 15:58
AppleBookScrollDemo
//
// AppleBookScrollDemo.swift
// IOS18Playground
//
// Created by Codelaby on 26/2/25.
//
import SwiftUI
struct Book: Identifiable, Hashable, Sendable {
@Codelaby
Codelaby / NumerciHPicker.swift
Created February 26, 2025 11:14
NumerciHPicker
//
// NumerciHPicker.swift
// FieldsPlayground
//
// Created by Codelaby on 25/2/25.
//
import SwiftUI
struct NumerciHPicker<SelectionValue, Content>: View where SelectionValue: Hashable & Sendable, Content: View {
@Codelaby
Codelaby / SlimeProgressDotPageIndicator.swift
Created February 24, 2025 10:46
Slime Progress Dot Indicator
// MARK: Slime Progress Dot Indicator
struct SlimeProgressDotPageIndicator: View {
private let currentPage: Int
private let numberOfPages: Int
private let hidesForSinglePage: Bool
private let config: Config
private let progress: CGFloat
private var adjustedIndex: Int {
return currentPage < 0 ? numberOfPages : (currentPage > numberOfPages ? 0 : currentPage)