Created
December 3, 2021 05:13
-
-
Save Kazunari-h/30ee173d86e95917c2f17533eb446962 to your computer and use it in GitHub Desktop.
IP3S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Cell.swift | |
// marubatsu | |
// | |
// Created by 29MCGD016 on 2021/11/26. | |
// | |
import SwiftUI | |
struct Cell: View { | |
var boxState: Bool? | |
var action: () -> () | |
var body: some View { | |
Button(action: { | |
self.action() | |
}, label: { | |
if let _boxState = boxState { | |
Image(systemName: _boxState ? "circle" : "xmark") | |
} else { | |
// nil | |
Text("s") | |
.foregroundColor(.white) | |
} | |
}) | |
.padding(20) | |
.frame(width: 100, height: 100) | |
.background(Color.white) | |
.foregroundColor(boxState ?? true ? .red : .blue) | |
} | |
} | |
struct Cell_Previews: PreviewProvider { | |
static var previews: some View { | |
Cell {} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// marubatsu | |
// | |
// Created by 29MCGD016 on 2021/11/05. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@State var boxList: [[Bool?]] = [ | |
[nil, nil, nil], | |
[nil, nil, nil], | |
[nil, nil, nil] | |
] | |
var body: some View { | |
VStack(spacing: 1) { | |
ForEach(Array(zip(boxList.indices, boxList)), id: \.0) { (v, row) in // [Bool?] | |
HStack(spacing: 1) { | |
ForEach(Array(zip(row.indices, row)), id: \.0) { (h, boxState) in | |
Cell(boxState: boxState) { | |
boxList[v][h] = !(boxState ?? false) | |
} | |
} | |
} | |
} | |
} | |
.background(Color.black) | |
Button(action: { | |
// if box1 == nil { | |
// box1 = true | |
// } else { | |
// box1?.toggle() | |
// } | |
}, label: { | |
// if let _box1 = box1 { | |
// Image(systemName: _box1 ? "circle" : "xmark") | |
// } else { | |
// // nil | |
// Text("a") | |
// } | |
}) | |
.background(Color.red) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment