Updating Own Project To SwiftUI (HowManyLetters?) - Part 1
Finally getting round to this! A chance to really explore SwiftUI - just for an hour this evening. The idea is to update everything I did with 'HowManyLetters?' so it is compatible with SwiftUI. Moving forwards, it makes sense to have it all together on this. Let's give it a go!
Start Time - 19:08
OK, let's open the previous project and make a note of all we need..
*Paused for around 10 mins
Model
*I didn't actually build models of words before but it makes sense to try it again here
View
Title
Labels for score and question number
Word displayed
Click label
Click button (beagle)
Instruction label
Info button
New game button
Other view -
Title
Info on screen
Return button
Controller
Loads here....
Global variables - total, score instruction info label
Timer - seconds, timer object and time running
Wordbank of word array
All labels connected
Hide keyboard and Text field returning functions
Timer running
Updating timer
Pause timer
Reset timer
New word function - to get random number
New game, update scores, reset text box functions
Check if answer is correct
So what a cool, fully functioning app! Let's start with the main parts of the view today...
I've just opened Bullseye to get the code for the view etc.
Right, after a lot of playing around, here's what we have for the view!

Not bad eh!
Code wise, quite a bit....
Start Time - 19:08
OK, let's open the previous project and make a note of all we need..
*Paused for around 10 mins
Model
*I didn't actually build models of words before but it makes sense to try it again here
View
Title
Labels for score and question number
Word displayed
Click label
Click button (beagle)
Instruction label
Info button
New game button
Other view -
Title
Info on screen
Return button
Controller
Loads here....
Global variables - total, score instruction info label
Timer - seconds, timer object and time running
Wordbank of word array
All labels connected
Hide keyboard and Text field returning functions
Timer running
Updating timer
Pause timer
Reset timer
New word function - to get random number
New game, update scores, reset text box functions
Check if answer is correct
So what a cool, fully functioning app! Let's start with the main parts of the view today...
I've just opened Bullseye to get the code for the view etc.
Right, after a lot of playing around, here's what we have for the view!

Not bad eh!
Code wise, quite a bit....
mport SwiftUI
struct ContentView: View {
@State var alertIsVisible = false
var body: some View {
VStack {
HStack {
Text("Score:")
.padding(.leading, 10)
Text("0")
Spacer()
Text("Question:")
Text("1")
.padding(.trailing, 10)
}
Spacer()
VStack {
Text("How Many Letters?")
.font(.largeTitle)
}
Spacer(minLength: 40)
VStack {
Text("30")
.font(.title)
}
Spacer(minLength: 120)
VStack {
Button(action: {
self.alertIsVisible = true
}) {
Text("Click Here To Check!")
}
Spacer()
VStack {
Text("Longest word to go here")
.font(.title)
}
Spacer()
VStack {
TextField("", text: /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Value@*/.constant("")/*@END_MENU_TOKEN@*/)
.frame(width: 50.0, height: 50.0)
}
Spacer()
VStack {
Text("Enter the number of words in the box!")
.multilineTextAlignment(.center)
.padding(.horizontal, 120.0)
}
Spacer()
VStack {
HStack {
Button(action: {
self.alertIsVisible = true
}) {
Text("Info")
}
.padding(.leading, 10)
Spacer()
Button(action: {
self.alertIsVisible = true
}) {
Text("New Game")
}
.padding(.trailing, 10)
}
.padding(.bottom, 20)
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Still quite a bit to do but that's all I am for now. Mostly, it's getting the text field to be shown as it is actually there! That will be a job for another time - some help online needed.
Anyway, a good effort. View is done for now. Next job will be the Model, then the Controller. Then the jazzing up of the view with the various elements. This will be a project for at least a week but it will be time well spent!
Things I've picked up already -
When you have a button, the stacks can get a bit cramped. To specify the spacing, you can do an alternative Spacer with a parameter of minLength. That helps out a bit.
You can click on padding options for which edge you want to include, as well as size of objects. So it doesn't all have to be hard code basically - this is good for trying things out.
Finish Time - 20:42 (approx 1 hour 20 minutes)
Comments
Post a Comment