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 24, 2024 01:45
SwiftUIでアラートとシートを出し分ける
import SwiftUI
struct ContentView: View {
@State var numberString: String = ""
@State var showingAlert: Bool = false
@State var showingSheet: Bool = false
var body: some View {
VStack {
TextField("Input Number", text: $numberString)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:44
NavigationLinkを使用せずにプッシュ遷移する(.navigationDestination)
import SwiftUI
struct ContentView: View {
@State var isActive: Bool = false
var body: some View {
NavigationStack {
VStack {
Button(action: {
isActive = true
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:42
SwiftUIで続きを読む。。。ボタンがあるViewを実装する
import SwiftUI
struct ContentView: View {
private let aliceInWonderland = "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversations?”\nSo she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.\nThere was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, “Oh dear! Oh dear! I shall be late!” (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a w
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:41
ext中の文字の太さや色を変える
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("I")
.font(.system(size: 20).bold())
+ Text(" ❤️ ")
.foregroundStyle(Color.red)
+ Text("Snorlax")
@takoikatakotako
takoikatakotako / CardView.swift
Created October 24, 2024 01:37
FunctionBuilderを使ってViewに影をつける
import SwiftUI
struct CardView<Content>: View where Content: View {
let color: Color
let radius: CGFloat
let content: () -> Content
init(
color: Color = Color.gray.opacity(0.4),
radius: CGFloat = 8,
@takoikatakotako
takoikatakotako / CardViewModifier.swift
Created October 24, 2024 01:35
ViewModifierを使ってViewに影をつける
import SwiftUI
struct CardViewModifier: ViewModifier {
let color: Color
let radius: CGFloat
func body(content: Content) -> some View {
content
.padding(16)
.background(Color.white)
.cornerRadius(16)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:34
SwiftUIでリストを編集する
import SwiftUI
struct ContentView: View {
@State private var users = ["Paul", "Taylor", "Adele"]
var body: some View {
NavigationView {
List {
ForEach(users, id: \.self) { user in
Text(user)
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:32
SwiftUIでリストのセルをタップしてアラートを表示させる
import SwiftUI
struct ContentView: View {
@State var showingAlert = false
@State var pokemon: Pokemon?
let pokemons: [Pokemon] = [
Pokemon(id: 143, name: "Snorlax"),
Pokemon(id: 25, name: "Pikachu"),
Pokemon(id: 138, name: "Psyduck"),
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:31
SwiftUIで画面遷移先のViewから遷移元のメソッドを呼び出す
import SwiftUI
struct ContentView: View, MyProtocol {
@State var text: String = "My Text"
var body: some View {
NavigationView {
VStack {
Text(text)
NavigationLink(destination: SecondView(delegate: self)) {
Text("2nd View")
@takoikatakotako
takoikatakotako / ContentView.swift
Created October 24, 2024 01:29
SwiftUIでListViewからそれぞれ別のViewに遷移する
import SwiftUI
struct ContentView: View {
@State var pokemon: Pokemon?
var body: some View {
NavigationStack {
List (Pokemon.allCases) { pokemon in
Button {
self.pokemon = pokemon
} label: {