Skip to content

Instantly share code, notes, and snippets.

View imthath-m's full-sized avatar
💭
developmentMode

Mohammed Imthathullah imthath-m

💭
developmentMode
View GitHub Profile
@davidsteppenbeck
davidsteppenbeck / ColorIconLabelStyle.swift
Created October 22, 2020 12:32
A SwiftUI label style for icons with dynamic colored backgrounds.
/// Sets a colored rounded rectangle behind the icon.
struct ColorIconLabelStyle: LabelStyle {
/// The color behind the icon.
var color: Color
/// The corner radius of the color behind the icon.
@ScaledMetric private var radius: CGFloat = 5
func makeBody(configuration: Configuration) -> some View {
@davidsteppenbeck
davidsteppenbeck / PreviewProviderModifier.swift
Last active October 31, 2022 10:30
A SwiftUI view modifier for simple preview providers.
import SwiftUI
enum PreviewProviderMode: CaseIterable {
/// Use for a light appearance preview.
case lightMode
/// Use for a dark appearance preview.
case darkMode
@magnuskahr
magnuskahr / EnumPicker.swift
Last active May 24, 2024 23:52
A simple picker to pick a enum.
import SwiftUI
struct EnumPicker<T: Hashable & CaseIterable, V: View>: View {
@Binding var selected: T
var title: String? = nil
let mapping: (T) -> V
var body: some View {
//
// ContentView.swift
//
//
// Created by Bernstein, Joel on 7/4/20.
//
import SwiftUI
struct ElementModel: Identifiable
@AliSoftware
AliSoftware / Demo.swift
Last active October 31, 2023 12:25
NestableCodingKey: Nice way to define nested coding keys for properties
struct Contact: Decodable, CustomStringConvertible {
var id: String
@NestedKey
var firstname: String
@NestedKey
var lastname: String
@NestedKey
var address: String
enum CodingKeys: String, NestableCodingKey {
//
// BottomSheetView.swift
//
// Created by Majid Jabrayilov
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
fileprivate enum Constants {
static let radius: CGFloat = 16
@alladinian
alladinian / SwiftUICocoaApp.swift
Last active April 21, 2022 18:21
A super simple Cocoa App boilerplate for SwiftUI prototyping _without_ Xcode
import Cocoa
import SwiftUI
func startApp(content: NSView) {
let app = NSApplication.shared
let menubar = NSMenu()
let appMenuItem = NSMenuItem()
let appMenu = NSMenu()
let appName = ProcessInfo.processInfo.processName
let quitTitle = "Quit \(appName)"
@Amzd
Amzd / UIKitTabView.swift
Last active March 16, 2024 10:40
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem
@raphaelhanneken
raphaelhanneken / NSImageExtensions.swift
Last active August 24, 2023 01:04
NSImage extensions for easy resizing, cropping and saving png images.
//
// NSImageExtensions.swift
//
import Cocoa
extension NSImage {
/// The height of the image.
var height: CGFloat {