Skip to content

Instantly share code, notes, and snippets.

View takoikatakotako's full-sized avatar

Kabigon Ono takoikatakotako

View GitHub Profile
@takoikatakotako
takoikatakotako / CalendarView.swift
Created October 24, 2024 00:20
SwiftUIを使ったTODOアプリのサンプル
import SwiftUI
struct CalendarView: UIViewRepresentable {
let didSelectDate: (_ dateComponents: DateComponents) -> Void
final public class Coordinator: NSObject, UICalendarSelectionSingleDateDelegate {
let didSelectDate: (_ dateComponents: DateComponents) -> Void
init(
didSelectDate: @escaping (_ dateComponents: DateComponents) -> Void
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 00:17
SwiftUIでAVAudioPlayerで音楽を再生し、再生終了を検知する
import SwiftUI
struct ContentView: View {
@StateObject var viewModel = ContentViewState()
var body: some View {
VStack {
Button("Play") {
viewModel.playAudio()
}
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 00:14
SwiftUIでモーダルを表示する時に値を渡す
import SwiftUI
struct ContentView: View {
@State var name = ""
@State var showingSheet = false
var body: some View {
VStack(spacing: 16) {
TextField("Input Name", text: $name)
.textFieldStyle(RoundedBorderTextFieldStyle())
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 00:12
SwiftUIでBMIを計算し、結果を別のViewで表示する
import SwiftUI
struct ContentView: View {
@State var height: String = ""
@State var weight: String = ""
@State var bmi: Double = 0
@State var showingSheet = false
var body: some View {
VStack {
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 16:31
SwiftUIでボタンを押すとポップアップを表示する
import SwiftUI
struct ContentView: View {
@State var showingPopUp = false
var body: some View {
ZStack {
Button(action: {
withAnimation {
showingPopUp = true
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 16:26
SwiftUIでViewを横スクロールで表示する
import SwiftUI
struct ContentView: View {
var body: some View {
let pokemons = ["pikachu", "slowpoke", "bellsprout", "ditto", "snorlax", "eevee", "magikarp"]
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 12) {
ForEach(pokemons, id: \.self) { pokemon in
Image(pokemon)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 16:24
SwiftUIでButtonを有効にしたり無効にしたりする
import SwiftUI
struct ContentView: View {
@State var enable: Bool = true
var body: some View {
VStack {
Toggle(isOn: $enable) {
Text("isEnable: \(enable.description)")
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 16:19
SwiftUIのTextFieldで表示するキーボードを指定する
import SwiftUI
struct ContentView: View {
@State var numberString = ""
var body: some View {
TextField("Input Number", text: $numberString)
.keyboardType(.decimalPad)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 16:17
SwiftUIでシートを表示し、プッシュ遷移後にシートを閉じる
import SwiftUI
struct ContentView: View {
@State var showingSheet: Bool = false
var body: some View {
Button(action: {
showingSheet = true
}, label: {
Text("ShowSheet")
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 16:15
SwiftUIでListをEditModeにして並び替える
import SwiftUI
struct ContentView: View {
@State var pokemons: [Pokemon] = [
Pokemon(id: 143, name: "Snorlax"),
Pokemon(id: 52, name: "Meowth"),
Pokemon(id: 25, name: "Pikachu")
]
var body: some View {