Skip to content

Instantly share code, notes, and snippets.

@zunda-pixel
zunda-pixel / 等幅画像.swift
Created August 14, 2023 09:20
等幅画像 SwiftUI
struct ContentView: View {
let urls: [URL] = [
.init(string: "https://webcg.ismcdn.jp/mwimgs/0/f/640wm/img_0f0ccf94fbdcfab41992550a42460808110746.jpg")!,
.init(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Tour_Eiffel_Wikimedia_Commons_%28cropped%29.jpg/640px-Tour_Eiffel_Wikimedia_Commons_%28cropped%29.jpg")!,
]
var body: some View {
ScrollView {
LazyVStack(spacing: 40) {
ForEach(urls, id: \.self) { url in
@zunda-pixel
zunda-pixel / SampleApp.swift
Last active June 22, 2023 09:32
SwiftData Relationship(cascade, inverse) delete bug
// 1. Add Person
// 2. Add Car
// 3. Delete Person(or Car)
import SwiftUI
import SwiftData
@main
struct Xcode17_SampleApp: App {
var body: some Scene {
@zunda-pixel
zunda-pixel / NavigationSplitView+tint.swift
Last active June 2, 2023 16:08
NavigationSplitView's sidebar doesn't support tint
struct ContentView: View {
@State var selection: Int? = 0
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(0..<10) { i in
Text("Data \(i)")
.tag(i)
}
@zunda-pixel
zunda-pixel / NavigationSplitView+TabView+toolbar(.hidden).swift
Last active March 6, 2024 14:22
.toolbar(.hidden, for: .tabBar) does not work when multiple tab change
import SwiftUI
enum TabItem: String, CaseIterable, Hashable, Identifiable {
case first
case second
case third
var id: Self { self }
}
@zunda-pixel
zunda-pixel / Environment-openURL-bug.swift
Created January 15, 2023 09:22
Environment openURL NavigationLink Bug?
// Previewだと動くがシミュレーターだと動かない
// 原因? Environment(\.openURL), NavigationLink
struct ContentView: View {
let urls: [URL] = [
URL(string: "https://github.com")!,
URL(string: "https://github.com")!,
URL(string: "https://github.com")!,
]
@zunda-pixel
zunda-pixel / ContentView.swift
Last active December 15, 2022 10:43
.toolbarBackground(.visible, for: .navigationBar) has no padding
struct ContentView: View {
@State var text = ""
var body: some View {
NavigationStack {
List {
TextField("Text", text: $text)
}
//.padding(.top, 10)
.toolbarBackground(.visible, for: .navigationBar)
@zunda-pixel
zunda-pixel / ContentView.swift
Created December 10, 2022 06:49
LocationButton tint bug?
import SwiftUI
import CoreLocationUI
struct ContentView: View {
let colors: [Color] = [
.white,
Color(.secondarySystemGroupedBackground),
Color(.lightText),
Color(.systemBackground),
@zunda-pixel
zunda-pixel / ContentView.swift
Created October 13, 2022 09:14
SwiftUI Layout Challenge 009
//
// ContentView.swift
//
import SwiftUI
struct AppInfo: Identifiable, Equatable {
let id = UUID()
let color: Color
let name: String
@zunda-pixel
zunda-pixel / ContentView.swift
Created October 7, 2022 00:37
複数@ObservedObjectの罠(onAppearが動作しない。してるけどselfが初期化されてしまう)
//
// ContentView.swift
//
import SwiftUI
struct ContentView: View {
@State var path = NavigationPath()
var body: some View {
@zunda-pixel
zunda-pixel / ContentView.swift
Created October 4, 2022 08:57
SwiftIU searchable, searchScopes, searchSuggestions
import SwiftUI
struct ContentView: View {
@State var searchText: String = ""
@State var dogType: DogType = .all
@State var searchHistory: [String] = ["choco", "kinako", "malon"]
let dogs: [Dog] = [
.init(name: "mugi", color: .orange, type: .poodle),
.init(name: "mugi", color: .red, type: .chihuahua),