UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

WordScramble: how do i get the systemImage and Text showing in the same row?

Forums > SwiftUI

Hello all,

To whoever can help, I've been trying to figure out what's wrong with my code but not sure where i'm going wrong. when putting the image systemName and Text inside the list, they're meant to automatically be put into a HStack by swift so they show on the same line is what i've understood but they show on different rows/lines for me.

struct ContentView: View {

    @State private var usedWords = [String]()
    @State private var rootWord = ""
    @State private var newWord = ""

    @State private var score = 0

    @State private var errorTitle = ""
    @State private var errorMessage = ""
    @State private var showingError = false

    var body: some View {
        NavigationView{
            VStack{

                TextField("Enter word", text: $newWord, onCommit: addNewWord)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .autocapitalization(.none)
                    .padding()

                    List(usedWords, id: \.self){
                        Image(systemName: "\($0.count).circle")
                        Text($0)
                    }
                Text("You currently have a score of: \(score)")
            }
            .navigationBarTitle(rootWord)
            .toolbar {
                ToolbarItem(placement: .navigationBarLeading){
                    Button("Start New Game", action: startGame)
                }
            }
            .onAppear(perform: startGame)
            .alert(isPresented: $showingError){
                Alert(title: Text(errorTitle), message: Text(errorMessage), dismissButton: .default(Text("OK")))
            }
        }

    }

2      

See this post.

HStack has changed for Xcode 13.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.