SwiftUI - Image and text in the same line

Viewed 40

Lately started learning SwiftUI and I ran into a problem. I tried putting image and text component and it didn't break the line. enter image description here

Someone have an idea to solve it?

This is my code:

struct RestaurantOverlay: View {
    var amountOfStars: Int
    var body: some View {
        ZStack {
            Text("Burger")
                .font(.system(size: 17.5))
                .foregroundColor(.white)
                .fontWeight(.heavy)
            
            Image(systemName: "star.fill")
                .font(.system(size: 13))
                .foregroundColor(.white)
                .fontWeight(.medium)
        }
        .padding(10)
        .background(Color.black)
        .opacity(0.8)
        .cornerRadius(10.0)
    }
}
1 Answers
ZStack {
    HStack {
        Text("Burger")
                    .font(.system(size: 17.5))
                    .foregroundColor(.white)
                .fontWeight(.heavy)
        Image(systemName: "star.fill")
            .font(.system(size: 13))
            .foregroundColor(.white)
            .fontWeight(.medium)
    }
    .padding(10)
    .background(Color.black)
    .opacity(0.8)
    .cornerRadius(10.0)
    }

You can change HStack to VStack if you want vertically.

Related