NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

2021.4.6 I will finish the project three.

Forums > 100 Days of SwiftUI

Thanks all the source of Swift, the team,that give me a lot of improvements.

   

This is challenge three of project three.

struct flagImage:View{ var a:String var body:some View{ Image(a) .renderingMode(.original) .shadow(color:.purple,radius:50) .overlay(Rectangle().stroke(Color.black,lineWidth:2)) .clipShape(RoundedRectangle(cornerRadius: /@START_MENU_TOKEN@/25.0/@END_MENU_TOKEN@/))

}

} //call the struct flagImage(a: // the name of the image)

I finished the project three. Thanks,again.

   

I design a game of rock,scissor,and paper,however,it differs with the requirement of Paul's,but I think it is my first design authentically,so I share with everybody. May it is not so good,I love it at least,that's enough.

import SwiftUI

struct ContentView: View { //2.make an array of String,and we need it refreshes after end every time. @State var gamechoice=["✊","✂️","👋"].shuffled() //3.产生一个随机数 @State var number = Int.random(in:0...2) @State var click1=true @State var click2=true @State var click3=true //4.刷新数组和序号 func gameagain(){ gamechoice.shuffle() number=Int.random(in:0...2) } func result1()->String{ if gamechoice[number]=="✊"{ return "👋"

    }else if gamechoice[number]=="✂️"{
        return "✊"
}else {
           return  "✂️"
        }

}
func result2()->String{
    if gamechoice[number]=="✊"{
        return "✂️"

    }else if gamechoice[number]=="✂️"{
        return "👋"
}else {
           return  "✊"
        }

}
func same(){
    if click1==true{
        click2=true
        click3=true
    }
}
var body: some View {
   //1.place three Text,one for computer,one for winner,the last one for loser.
    VStack{
        Button(action:{
            click1.toggle()
            same()
            gameagain()
        }){
            Text(click1 ? "电脑":gamechoice[number])
                .usemyview()
        }

        Section{
                HStack(spacing:85){
                    Button(action:{
                        click2.toggle()
                       // gameagain()
                    }){
                        Text(click2 ? "winner":result1())

                            .usemyview()
                }

                Button(action:{
                    click3.toggle()
                }){
                    Text(click3 ? "loser":result2())
                        .usemyview()
                }
            }
        }
    }
}

}

struct myview:ViewModifier{ func body(content: Content) -> some View { content .font(.title) .frame(width: 80, height: 30, alignment: /@START_MENU_TOKEN@/.center/@END_MENU_TOKEN@/) .padding() .foregroundColor(.black) .background(Color.green) .clipShape(RoundedRectangle(cornerRadius:20)) } } extension View{ func usemyview()->some View{ self.modifier(myview()) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }

   

I have finished the project four,but I need to conclude it,for the reason that Core ML(Machine Learning) is very difficult. Actually,I think that most of us need review what we have learned frequently,I always forget how to use some modifier,how to create a view,and how to write the syntax of the nil coalescing so on. I will continue studying,only persist can we become a real ios developer.

   

Hacking with Swift is sponsored by Stream

SPONSORED Check out Stream's cross-platform open source chat SDK on GitHub! Write once and deploy your app with fully featured chat UI on iOS and macOS.

Go to GitHub

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.