美文网首页
SwiftUI-单张事项卡片

SwiftUI-单张事项卡片

作者: 脑子 | 来源:发表于2020-11-22 22:41 被阅读0次
    
    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()
        }
    }
    
    
    image.png

    相关文章

      网友评论

          本文标题:SwiftUI-单张事项卡片

          本文链接:https://www.haomeiwen.com/subject/agbpiktx.html