SwiftUI程序员

SwiftUI Button

2020-07-27  本文已影响0人  Lee_dev
swiftui-button.png
import SwiftUI

struct ContentView: View {
    
    @State var number: Int = 0
    
    var body: some View {
        VStack {
            ///显示结果的空间
            Text("\(number)")
                .font(.system(size: 100))
                .foregroundColor(.blue)
            
            HStack {
                Spacer()
                ///加 1 按钮
                Button(action: {
                    self.number += 1
                }) {
                    HStack {
                        Image(systemName: "plus.circle")
                            .font(.title3)
                        Text("plus")
                            .font(.title3)
                    }.padding()
                    .frame(width: 120, height: 44, alignment: .center)
                    .background(Color.green)
                    .foregroundColor(.white)
                    .cornerRadius(10)
                }
                
                Spacer()
                ///减 1 按钮
                Button(action: {
                    self.number -= 1
                }) {
                    HStack {
                        Image(systemName: "minus.circle")
                            .font(.title3)
                        Text("minus")
                            .font(.title3)
                    }.padding(10)
                    .frame(width: 120, height: 44, alignment: .center)
                    .background(Color.red)
                    .foregroundColor(.white)
                    .cornerRadius(10)
                    
                }
                Spacer()
            }
            
        }
    }
}

上一篇 下一篇

猜你喜欢

热点阅读