Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does swiftui limit number of Spacer()?

This code is something similar to my current UI. I have alot of view in between of Spacer(). I notice that when i add alot of Spacer() i get this error //Trailing closure passed to parameter of type ‘HorizontalAlignment’ that does not accept a closure// why is that?

import SwiftUI

 struct Phrases2: View {
   var body: some View {
    ZStack() {
        Text("")
        Text("")
        VStack() {
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
            Text("")
            Spacer()
        }
    }
  }
  }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The issue here is the number of views in the stack. ViewBuilder in SwiftUI allows you to have up to 10 views in the HStack/VStack/List.

You can avoid the issue using Groups:

VStack {
    Group {
        Text("")
        Spacer()
        Text("")
        Spacer()
        Text("")
        Spacer()
    }
    Group {
        Text("")
        Spacer()
        Text("")
        Spacer()
        Text("")
        Spacer()
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading