import SwiftUI
struct ContentView: View {
//@State属性包装器,isChecked是一种State,编译器会一直盯着,如果isChecked改变则所有用到它的视图都要更新
@State var isChecked: Bool = false
var body: some View {
HStack {
Rectangle()
.frame(width: 6)
.foregroundColor(.blue)
VStack(alignment: .leading, spacing: 6) {
Text("写作业")
.font(.headline)
.fontWeight(.heavy)
Text("2020.02.02")
.font(.subheadline)
.foregroundColor(Color.gray)
}
.padding(.leading)
Spacer()
Image(systemName: self.isChecked ? "checkmark.square.fill" : "square")
.imageScale(.large)
.padding(.trailing)
.onTapGesture {
self.isChecked.toggle()
}
}
.frame(height: 80)
.background(Color.white)
.cornerRadius(10)
.shadow(radius: 10, x: 0, y: 10)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
![](https://img.haomeiwen.com/i1776147/51d166b972fa5573.png)
image.png
网友评论