Skip to content

Instantly share code, notes, and snippets.

@hirauchg
hirauchg / FirstView.swift
Last active August 20, 2020 13:56
他のViewのイベントから画面遷移
struct FirstView: View {
@State var flug: Bool = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: SecondView(), isActive: $flug) {
EmptyView()
}
@hirauchg
hirauchg / FirstView.swift
Created August 20, 2020 13:45
有効・無効の切り替え
struct FirstView: View {
@State var isDisable: Bool = false
var body: some View {
NavigationView {
VStack {
Toggle(isOn: $isDisable) {
Text("リンクを無効にする")
}.frame(width: 220)
@hirauchg
hirauchg / FirstView.swift
Created August 20, 2020 13:32
カスタムビューのNavigationLinkの実装
struct FirstView: View {
var body: some View {
NavigationView {
NavigationLink(destination: SecondView()) {
VStack {
Image("neko").renderingMode(.original)
Text("ネコ")
}
}
@hirauchg
hirauchg / FirstView.swift
Created August 20, 2020 13:10
テキストのNavigationLinkの実装
struct FirstView: View {
var body: some View {
NavigationView {
NavigationLink("画面遷移", destination: SecondView())
}
}
}
@hirauchg
hirauchg / ContentView.swift
Last active August 19, 2020 13:43
ボタンのスタイルの変更
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(spacing: 20) {
Button(action: {}) {
Text("Button").font(.title)
}
.buttonStyle(DefaultButtonStyle())
@hirauchg
hirauchg / ContentView.swift
Last active August 19, 2020 13:12
画像などのカスタムボタンの実装
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {
// タップ時の処理を実装
}) {
Image("download")
Text("ダウンロード")
@hirauchg
hirauchg / ContentView.swift
Created August 19, 2020 12:43
テキストのボタンの実装
import SwiftUI
struct ContentView: View {
@State var text = "ボタンをタップしてください。"
var body: some View {
VStack {
Button("ボタン") {
self.text = "タップされました。"
@hirauchg
hirauchg / ContentView.swift
Created August 18, 2020 08:55
画像の色を変更する
struct ContentView: View {
var body: some View {
VStack {
Image("soccer")
Image("soccer")
.renderingMode(.template)
.foregroundColor(.red)
}
}
@hirauchg
hirauchg / ContentView.swift
Created August 18, 2020 08:19
画像を敷き詰めて表示する
struct ContentView: View {
var body: some View {
VStack {
Image("soccer")
.resizable(capInsets: .init(), resizingMode: .tile)
.frame(width: 300, height: 300)
Image("soccer")
.resizable(capInsets: .init(), resizingMode: .stretch)
.frame(width: 300, height: 300)
@hirauchg
hirauchg / ContentView.swift
Created August 18, 2020 07:54
画像のサイズを変更する
struct ContentView: View {
var body: some View {
VStack {
Image("soccer")
Image("soccer")
.resizable()
.scaledToFit()
.frame(width: 200, height: 100)
Image("soccer")