Skip to content

Instantly share code, notes, and snippets.

View takoikatakotako's full-sized avatar

Kabigon Ono takoikatakotako

View GitHub Profile
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:47
SwiftUIでインディケーターを表示する
import SwiftUI
struct ContentView: View {
@State var showingIndicator = true
var body: some View {
ZStack {
VStack {
Spacer()
Button {
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:46
SwiftUIで少しカスタマイズしたインディケーターを表示する
import SwiftUI
struct ContentView: View {
@State var showingIndicator = true
var body: some View {
ZStack {
VStack {
Spacer()
Button {
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:41
SwiftUIでListにButtonを設定して異なる画面に遷移する
import SwiftUI
struct ContentView: View {
@State var pokemon: Pokemon?
var body: some View {
NavigationStack {
List {
Button {
pokemon = .snorlax
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:38
SwiftUIのTabViewのタブをコードから動的に切り替える
import SwiftUI
struct ContentView: View {
@State var selection: Int = 0
var body: some View {
TabView(selection: $selection) {
FirstView(selection: $selection)
.tabItem {
Image(systemName: "house")
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:30
SwiftUIでスライダーとスクロールを連動させる
import SwiftUI
struct ContentView: View {
@State var percent: Double = 0
let text = """
Fly me to the moon
Let me sing among those stars
Let me see what spring is like
On jupiter and mars
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:15
SwiftUIでPHPickerViewControllerを使って画像を選択する
import SwiftUI
struct ContentView: View {
@State var image: UIImage?
@State var showingAlert: Bool = false
var body: some View {
VStack {
if let image = image {
Image(uiImage: image)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 23, 2024 12:06
SwiftUIでPageControlを使用する
import SwiftUI
struct ContentView: View {
@State var views = [
TutorialView(image: Image(.snorlax), text: "First"),
TutorialView(image: Image(.pikachu), text: "Second"),
TutorialView(image: Image(.slowpoke), text: "Third"),
TutorialView(image: Image(.magikarp), text: "Fourth"),
]
@takoikatakotako
takoikatakotako / Column.swift
Created June 7, 2024 01:25
SwiftUIで表を作る
import Foundation
struct Column: Hashable {
let title: String
let rows: [String]
}
@takoikatakotako
takoikatakotako / ContentView.swift
Created May 3, 2024 16:46
Swiftのasync,awaitを使ってAPIと画像を取得し、全てが揃ってから表示する
import SwiftUI
struct ContentView: View {
@State var pokemons: [Pokemon] = []
var body: some View {
VStack {
ForEach(pokemons) { pokemon in
HStack {
Image(uiImage: pokemon.image)
@takoikatakotako
takoikatakotako / AddItemView.swift
Created May 3, 2024 16:43
SwiftUIでObservableObjectの@publishedなプロパティとBindingする
import SwiftUI
struct AddItemView: View {
@StateObject var viewState: AddItemViewState
init(items: Binding<[String]>) {
self._viewState = StateObject(wrappedValue: AddItemViewState(items: items))
}
var body: some View {