Artemis_Dev
Artemis_Dev

Reputation: 51

Invalid frame dimension (negative or non-finite)

I'm new to this platform but swift is giving me a headache it is seeming to have a problem with the value (Infinity) although what should I put instead?

 .bold()
 .frame(width: .infinity, height: 20, alignment: .topLeading)
 Text(course.type)
 .font(.system(size: 15, weight: .light))
 .frame(width: .infinity, height: 10, alignment: .topLeading )
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
                Button {
                    openURL(URL(string: course.link)!)
                       }
            label: {
                Text("GET").bold()
                    .frame(width: 35, height: 1)
                  
                    .padding()
                    .foregroundColor(Color(.white))
                    .background(Color(.orange))
              
                    .cornerRadius(25)
}
}.frame(width: .infinity, height: .infinity)
.padding()

Upvotes: 5

Views: 5802

Answers (4)

charles
charles

Reputation: 41

Your frame was not properly set width and height for frame

Please use this like a frame

frame(minWidth: 0,maxWidth: .infinity,minHeight: 0,maxHeight: .infinity,alignment: .center)

Upvotes: 3

CoolPineapple
CoolPineapple

Reputation: 385

In my case, the error was coming from the amount of padding I was adding, since there was an edge case where my calculated padding came out as nan, which crashed the app. So if anyone else gets stuck tracking down this bug, I would suggest looking through the attributes to find any calculated value that might have a math mistake in it.

Upvotes: 0

George
George

Reputation: 30441

An infinite width or height doesn't make sense. If instead you want the view to expand as much as possible, use the maxWidth and maxHeight variants instead:

.frame(maxWidth: .infinity, maxHeight: .infinity)

Upvotes: 9

BPS
BPS

Reputation: 365

Try only setting a frame when you have to, and use .none instead of .infinity.

Upvotes: 2

Related Questions