Skip to content

Instantly share code, notes, and snippets.

View sarunw's full-sized avatar
🍎
iOS, Swift, SwiftUI

Sarun Wongpatcharapakorn sarunw

🍎
iOS, Swift, SwiftUI
View GitHub Profile
@sarunw
sarunw / 1_SFSymbols.scpt
Created May 24, 2023 09:53 — forked from diamantidis/1_SFSymbols.scpt
How to use AppleScript to generate an enum for the SF Symbols
activate application "SF Symbols"
tell application "System Events"
tell process "SF Symbols"
-- Click the “list” radio button.
click radio button 2 of radio group 1 of group 3 of toolbar 1 of window 0
tell outline 1 of scroll area 1 of splitter group 1 of window 0
select (row 1 where value of static text 1 of UI element 1 starts with "All")
class FloatingPanel: NSPanel {
init(contentRect: NSRect, backing: NSWindow.BackingStoreType, defer flag: Bool) {
// Not sure if .titled does affect anything here. Kept it because I think it might help with accessibility but I did not test that.
super.init(contentRect: contentRect, styleMask: [.nonactivatingPanel, .resizable, .closable, .fullSizeContentView], backing: backing, defer: flag)
// Set this if you want the panel to remember its size/position
// self.setFrameAutosaveName("a unique name")
// Allow the pannel to be on top of almost all other windows
@sarunw
sarunw / LandscapeModifier.swift
Created March 16, 2021 03:43
Preview a device in landscape with SwiftUI Previews
struct LandscapeModifier: ViewModifier {
let height = UIScreen.main.bounds.width
let width = UIScreen.main.bounds.height
var isPad: Bool {
return height >= 768
}
var isRegularWidth: Bool {
return height >= 414
@sarunw
sarunw / extractViewsFromContent.swift
Created December 30, 2020 08:37 — forked from stleamist/extractViewsFromContent.swift
An experimental way to extract SwiftUI views from an TupleView built by ViewBuilder.
import SwiftUI
func extractViewsFromContent<Content: View> (@ViewBuilder content: () -> Content) -> [Any] {
let tupleView = content()
let tupleViewMirror = Mirror(reflecting: tupleView)
let tuple = tupleViewMirror.children.first!.value
let tupleMirror = Mirror(reflecting: tuple)
let views = tupleMirror.children.map { $0.value }
return views
}
// SwiftUI Custom Styles (TripleToggleStyle)
// https://swiftui-lab.com
// https://swiftui-lab.com/custom-styling
import SwiftUI
// MARK: - TripleToggle View
public struct TripleToggle: View {
@Environment(\.tripleToggleStyle) var style: AnyTripleToggleStyle
@sarunw
sarunw / UIColor.swift
Created October 7, 2020 12:46 — forked from nbasham/UIColor.swift
Swift 4: Convert CSS color names and RGB hex values to UIColor. UIColor from hex 3, 4, 6, and 8 characters in length with or without # prefix. UIColor to hex. UIColor extension that creates immutable UIColor instances from hexadecimal and CSS color name strings (e.g. ff0, #f00, ff0000, ff0000ff, Pink, aZure, CLEAR, nil). Conversely, you can obta…
//
// UIColor.swift
// previously Color+HexAndCSSColorNames.swift
//
// Created by Norman Basham on 12/8/15.
// Copyright ©2018 Black Labs. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@sarunw
sarunw / Lottie.stencil
Created July 17, 2020 15:43 — forked from djbe/Lottie.stencil
SwiftGen template for Lottie animations
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if files %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
{% set documentPrefix %}{{param.documentName|default:"Document"}}{% endset %}
import Lottie
import UIKit
// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlxrwmuYSAsTfn+lUu4go
ZSXBD9ackM9OJuwUVQHmbZo6GW4Fu/auUdN5zI7Y1dEDfgt7m7QXWbHuMD01HLnD
4eRtY+RNwCWdjNfEaY/esUPY3OVMrNDI15Ns13xspWS3q+13kdGv9jHI28P87RvM
pjz/JCpQ5IM44oSyRnYtVJO+320SB8E2Bw92pmrenbp67KRUzTEVfGU4+obP5RZ0
9OxvCr1io4KJvEOjDJuuoClF66AT72WymtoMdwzUmhINjR0XSqK6H0MdWsjw7ysy
d/JhmqX5CAaT9Pgi0J8lU/pcl215oANqjy7Ob+VMhug9eGyxAWVfu/1u6QJKePlE
+wIDAQAB
-----END PUBLIC KEY-----
@sarunw
sarunw / mac-keys-unicode.md
Created October 24, 2019 17:59 — forked from zmwangx/mac-keys-unicode.md
Unicode characters for special keys on the Mac keyboard (not necessarily Mac specific). #symbols

⌘ – &#x2318;&#8984; – the Command Key symbol
⌥ – &#x2325;&#8997; – the Option Key symbol
⇧ – &#x21E7;&#8679; – the Shift Key symbol
⌃ – &#x2303;&#8963; – the Control Key symbol
⎋ – &#x238B;&#9099; – the ESC Key symbol
⇪ – &#x21ea;&#8682; – the Capslock symbol
⏎ – &#x23ce;&#9166; – the Return symbol
⌫ – &#x232b;&#9003; – the Delete / Backspace symbol
⇥ – &#x21E5;&#8677; – the Tab Key symbol

@sarunw
sarunw / google-service-env.sh
Created August 22, 2019 05:20
Xcode script for support multiple env Google service.
echo "copy from GoogleService-Info-$CONFIGURATION.plist to $SRCROOT/[PROJECT_NAME]/GoogleService-Info.plist"
cp "$SRCROOT/[PROJECT_NAME]/GoogleService-Info-$CONFIGURATION.plist" "$SRCROOT/[PROJECT_NAME]/GoogleService-Info.plist"
echo "Clean up"
find "$SRCROOT/[PROJECT_NAME]/container/" -not -path '*/\.*' -type f -maxdepth 1 -delete
if [ "${CONFIGURATION}" = "Debug" ] || [ "${CONFIGURATION}" = "Release" ]; then
echo "copy from $SRCROOT/[PROJECT_NAME]/container/Release/ to $SRCROOT/[PROJECT_NAME]/container/"
cp -r "$SRCROOT/[PROJECT_NAME]/container/Release/" "$SRCROOT/[PROJECT_NAME]/container/"