Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a constant for the maximum CGFloat value?

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

like image 510
Proud Member Avatar asked Jun 08 '11 20:06

Proud Member


People also ask

Is CGFloat double or float?

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.

What is CGFloat?

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.

What is the difference between the float double and CGFloat data types?

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.


1 Answers

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.

like image 78
GBF_Gabriel Avatar answered Sep 22 '22 03:09

GBF_Gabriel