Is there a constant for the maximum CGFloat value?

47,758

Solution 1

CGGeometry defines:

#define CGFLOAT_MAX FLT_MAX

Solution 2

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.

Solution 3

How about CGFLOAT_MAX?

Solution 4

I was looking for a Swift version of minimum CGFloat value and landed here, if you too ;) then here is the answer:

CGFloat.leastNormalMagnitude

Solution 5

A CGFloat is just a float so you can safely use FLT_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 than FLT_MAX, even though they are the same thing on 32 bit platforms.

Share:
47,758
Proud Member
Author by

Proud Member

Eu gosto de queijo, pizza, e programação.

Updated on July 08, 2022

Comments

  • Proud Member
    Proud Member almost 2 years

    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"?