Is there a constant for the maximum CGFloat value?

Proud Member picture Proud Member · Jun 8, 2011 · Viewed 45.3k times · Source

I need to create a CGSize to compute text height of an arbitrary text with arbitrary length. UIKit has this nice method -sizeWithFont:constrainedToSize: and my text is only constrained in width, but not in height.

For this, I need to set the maximum possible CGFloat for the height.

Is there a constant like "CGFloatMax"?

Answer

GBF_Gabriel picture GBF_Gabriel · Oct 4, 2014

For those using Swift 2, you should use:

CGFloat.max

For those using Swift 3, you should use:

CGFloat.greatestFiniteMagnitude

Note that CGFloat.max was removed when Swift 3 came out, as reflected in the documentation.