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"?
How about
CGFLOAT_MAX
?width = 0.0000000000000000000000000000000000000117549435, height = 3.40282347E+38
For those using Swift 2, you should use:
For those using Swift 3, you should use:
Note that
CGFloat.max
was removed when Swift 3 came out, as reflected in the documentation.In Swift 3.0, You can also use CGFloat(FLT_MAX), especially if you want to use it in other cases like zIndex, where CGFloat.greatestFiniteMagnitude will be out of range.
A
CGFloat
is just afloat
so you can safely useFLT_MAX
from<float.h>
.EDIT: As others have now pointed out it looks like
CGFLOAT_MAX
is already defined for you so you should use that for consistency rather thanFLT_MAX
, even though they are the same thing on 32 bit platforms.CGGeometry defines: