Skip to content

Instantly share code, notes, and snippets.

View takoikatakotako's full-sized avatar

Onojun takoikatakotako

View GitHub Profile
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 28, 2024 16:08
SwiftUIでSheetを表示する
import SwiftUI
struct ContentView: View {
@State var showingSheet = false
var body: some View {
VStack {
Button(action: {
showingSheet = true
}) {
Text("Tap me!")
@takoikatakotako
takoikatakotako / ContentView.swift
Last active October 28, 2024 16:02
Identifiableに適合していないStructでListを使う
import SwiftUI
struct ContentView: View {
let pokemons: [Pokemon] = [
Pokemon(name: "snorlax", type: "normal"),
Pokemon(name: "ditto", type: "normal"),
Pokemon(name: "psyduck", type: "water"),
Pokemon(name: "pikachu", type: "electric"),
]
@takoikatakotako
takoikatakotako / CameraView.swift
Created October 28, 2024 15:56
SwiftUIでカメラを使う
import SwiftUI
public struct CameraView: UIViewControllerRepresentable {
@Environment(\.dismiss) private var dismiss
@Binding var images: [UIImage]
public func makeCoordinator() -> Coordinator {
Coordinator(self)
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:55
Pickerを表示する
import SwiftUI
struct ContentView: View {
let pokemons = ["Snorlax", "Pikachu", "Slowpoke", "Meowth"]
@State var selectedPokemon = 0
var body: some View {
Picker("Pokemon", selection: $selectedPokemon) {
ForEach(pokemons, id: \.self) { pokemon in
Text(pokemon)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:53
画面遷移時に値を渡す
import SwiftUI
struct ContentView: View {
let fruits = ["Apple", "Banana", "Orange", "Grape", "Cherry", "Peach"]
var body: some View {
NavigationView {
List(fruits, id: \.self) { fruit in
NavigationLink(destination: SecondView(fruit: fruit)) {
Text(fruit)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:52
NavigationViewの戻るボタンを非表示にする
import SwiftUI
struct ContentView: View {
let fruits = ["Apple", "Banana", "Orange", "Grape", "Cherry", "Peach"]
var body: some View {
NavigationView {
List(fruits, id: \.self) { fruit in
NavigationLink(destination: SecondView(fruit: fruit)) {
Text(fruit)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:49
SwiftUIでListのスタイルを変更する(plain)
import SwiftUI
struct ContentView: View {
var body: some View {
List {
Section("Normal") {
Text("Meowth")
Text("Ditto")
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:48
Alertを表示する
import SwiftUI
struct ContentView: View {
@State var showingAlert = false
var body: some View {
VStack {
Button {
showingAlert = true
} label: {
@takoikatakotako
takoikatakotako / AlertItem.swift
Created October 24, 2024 01:47
SwiftUIでAlertを出し分ける
import Foundation
struct AlertItem {
let buttonTitle: String
let message: String
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:46
SwiftUIでButton内の画像やテキストの色を変えない
import SwiftUI
struct ContentView: View {
@State var bool = true
var body: some View {
VStack {
Text(bool ? "Snorlax" : "Forever")
Button(action: {
bool.toggle()