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"?
As others have said, CGFloat is a float on 32-bit systems and a double on 64-bit systems. However, the decision to do that was inherited from OS X, where it was made based on the performance characteristics of early PowerPC CPUs.
A CGFloat is a specialized form of Float that holds either 32-bits of data or 64-bits of data depending on the platform. The CG tells you it's part of Core Graphics, and it's found throughout UIKit, Core Graphics, Sprite Kit and many other iOS libraries.
Suggested approach: It's a question of how many bits are used to store data: Float is always 32-bit, Double is always 64-bit, and CGFloat is either 32-bit or 64-bit depending on the device it runs on, but realistically it's just 64-bit all the time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With