欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

006_swiftui_构建*应用

程序员文章站 2022-05-30 13:49:38
...

 效果展示

006_swiftui_构建*应用

代码预览

    //
    //  ContentView.swift
    //  Slots Demo
    //
    //  Created by liuan on 2020/3/31.
    //  Copyright © 2020 liuan. All rights reserved.
    //
    
    import SwiftUI
    
     struct ContentView: View {
        private var symbols=["apple","star","cherry"]
        @State private var numbers=[0,1,2]
         @State private var credits = 1000
        
        private var betAmout=5;
        var body: some View {
            ZStack{
                //bsckhtound
                Rectangle()
                    .foregroundColor(Color(red: 200/255, green: 143/255, blue: 32/255))
                    .edgesIgnoringSafeArea(.all)
                Rectangle()
                    .foregroundColor(Color(red: 228/255, green: 195/255, blue: 76/255))
                    .rotationEffect(Angle(degrees: 45))
                    .edgesIgnoringSafeArea(.all)
                 Spacer()
                
                VStack{
                     Spacer()
                    //title
                    HStack{
                        Image(systemName: "star.fill")
                            .foregroundColor(.yellow)
                        
                        Text("SwiftUi Slots")
                            .bold()
                            .foregroundColor(.white)
                        
                        Image(systemName: "star.fill")
                            .foregroundColor(.yellow)
                        
                    }.scaleEffect(2)
                     Spacer()
                    //Credits counter
                    Text("Credits:"+String(credits))
                        .foregroundColor(.black)
                        .background(Color.white.opacity(0.5))
                        .padding(.all,10)
                        .cornerRadius(20)
                       Spacer()
                    //cards
                    HStack{
                        Spacer()
                        Image(symbols[numbers[0]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(20)
                        
                        Image(symbols[numbers[1]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(20)
                        
                        Image(symbols[numbers[2]])
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .background(Color.white.opacity(0.5))
                            .cornerRadius(20)
                        Spacer()
                    }
                     Spacer()
                    
                    Button(action: {
                        //todo
                        self.credits += 1
                        self.numbers[0]=Int.random(in: 0...self.symbols.count-1)
                                self.numbers[1]=Int.random(in: 0...self.symbols.count-1)
                                self.numbers[2]=Int.random(in: 0...self.symbols.count-1)
                        //check winning
                        if self.numbers[0]==self.numbers[1]&&self.numbers[1]==self.numbers[2]{
                            self.credits+=self.betAmout*10
                        }else{
                            self.credits-=self.betAmout
                        }
                    }){
                        Text("Spin")
                            .bold()
                            .foregroundColor(.white)
                            .padding(.all,10)
                            .padding([.leading,.trailing],30)
                            .background(Color.pink)
                        .cornerRadius(20)
                    }
                    Spacer()
                    
                    
                }
                
                
                
            }
            
            
        }
    }
    
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }

需要用到的图片

https://download.csdn.net/download/mp624183768/12288003

相关标签: # swiftUI