Skip to content

Instantly share code, notes, and snippets.

import Foundation
import SwiftUI
#if os(macOS)
import AppKit
public typealias CrossPlatformColor = NSColor
#else
import UIKit
public typealias CrossPlatformColor = UIColor
#endif
@gewill
gewill / LinkButton.swift
Created February 13, 2023 15:21
LinkButton: show NavigationLink as a button in SwiftUI
import SwiftUI
/// https://stackoverflow.com/a/62853420
struct LinkButton<Destination: View, Label: View>: View {
let destination: Destination
let label: Label
let action: () -> Void
@State private var isActive = false
init(action: @escaping () -> Void, @ViewBuilder destination: @escaping () -> Destination, @ViewBuilder label: @escaping () -> Label) {
@gewill
gewill / FixedSizeButtonStyle.swift
Created December 14, 2022 03:28
Custom button style use PrimitiveButtonStyle on tvOS
import SwiftUI
struct FixedSizeButtonStyle: PrimitiveButtonStyle {
@FocusState private var isFocused: Bool
var size: CGSize
var cornerRadius: CGFloat
func makeBody(configuration: Configuration) -> some View {
configuration.label
.frame(width: size.width, height: size.height)
.foregroundColor(.accentColor)
@gewill
gewill / UserInterfaceIdiom.swift
Created December 5, 2022 05:29
UserInterfaceIdiom for all Apple platforms or devices.
enum UserInterfaceIdiom: Int {
case unspecified = -1
case phone = 0
case pad = 1
case tv = 2
case carPlay = 3
case mac = 5
case watch = 6
static var current: UserInterfaceIdiom {
@gewill
gewill / WebView.swift
Created November 29, 2022 15:19
WebView for macOS in SwiftUI
import SwiftUI
import WebKit
struct WebView: NSViewRepresentable {
typealias NSViewType = WKWebView
var html: String
func makeNSView(context: Context) -> WKWebView {
return WKWebView()
import SwiftUI
struct TestNextTextFieldFocus: View {
@State var inputsValues: [String] = (0..<30).map { i in
"test \(i) TextField axis is \(i % 2 == 0 ? ".vertical" : ".horizontal")"
}
@FocusState var focusedInput: Int?
var body: some View {
@gewill
gewill / remove_utm.user.js
Last active November 9, 2022 03:24 — forked from AndySuen/remove_utm.user.js
Remove utm parameters and medium hash tracking code from url / 去除网页链接中恼人的跟踪参数,网页内容可复制等
// ==UserScript==
// @name Remove utm
// @version 0.2.3
// @description Remove utm parameters and medium hash tracking code from url, 去除网页链接中恼人的跟踪参数
// @updateURL https://gist.github.com/AndySuen/09c480b2f90818b4fe0334e804e1dcc2/raw/remove_utm.user.js
// @homepage https://gist.github.com/AndySuen/09c480b2f90818b4fe0334e804e1dcc2
// @author Andysuen
// @match *://*/*
// @run-at document-idle
// @grant none
@gewill
gewill / xcode-beta-slink.sh
Created July 30, 2022 04:42 — forked from ethanhuang13/xcode-beta-slink.sh
Symbolic link from Xcode.app to Xcode-beta.app (Xcode 11.2)