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

How to use HStack to fill equally to the very edge of the View?

How can I make the HStack fill equally to the very edge of the View like yellow arrows indicate in the screenshot?

Here is the code:

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

var labelList = ["0", "6", "12", "6", "0"]
HStack {
    ForEach(labelList, id: \.self) { item in
        Text(item)
            .frame(maxWidth: .infinity)
            .font(.system(size: 8))
    }

Thanks.

>Solution :

Add Spacer after Text

var labelList = ["0", "6", "12", "6", "0"]
HStack {
    ForEach(labelList, id: \.self) { item in
        Text(item)
            .frame(maxWidth: .infinity)
            .font(.system(size: 8))
        if labelList.last != item {
            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