Questions tagged [cgfloat]

A CGFloat is the basic CoreGraphics type for all floating-point values in the Cocoa and Cocoa Touch UI frameworks.

A CGFloat is the basic CoreGraphics type for all floating-point values in the Cocoa and Cocoa Touch UI frameworks.

CGFloat is defined in the CGGeometry Reference of CoreGraphics, which defines structures for geometric primitives and functions that operate on them. Depending on your platform, a CGFloat is either 32 or 64 bits.

Use this tag when asking questions on CGFloat value types themselves, or CoreGraphics functions which use them.

207 questions
0
votes
1 answer

Is it safe to set a CGFloat to a double?

I have the following code running on a 64-bit device: CGFloat myFloat = 123.45f; CGFloat myDouble = 123.45; Is this safe across 32- and 64-bit devices? Since CGFloat changes sizes based on the processor architecture, will the given variables…
Ky -
  • 30,724
  • 51
  • 192
  • 308
0
votes
3 answers

Swift 2 - add decimal 0 to CGFloat

I am trying to convert a string into CGFloat number. The code I have cuts out the last digit if equal to 0. How can I prevent to cut out the zeros? let str = "17.30" let flt = CGFloat((str as NSString).doubleValue) + 2.0 print(flt) // 19.3 --…
SNos
  • 3,430
  • 5
  • 42
  • 92
0
votes
1 answer

Are SceneKit eulerAngles Floats or CGFloats?

According to the SceneKit API, euler angles, as a property of SCNNode, are SCNVector3. And SCNVector3 is { CGFloat x, y, z: }. But when I attempt to assign a CGFloat to a eulerAngle property of a node, Xcode claims I'm trying to assign to type…
bpedit
  • 1,176
  • 8
  • 22
0
votes
1 answer

Getting a random CGFloat value from an array?

I have an array that holds CGFloat values and I am trying to figure out how I would go about randomising through this array to get a random x co-ordinate: let xAxisSpawnLocations: [CGFloat] = [screenWidth + 150, screenWidth + 100, screenWidth + 50 ,…
Astrum
  • 375
  • 6
  • 21
0
votes
3 answers

heightForRowAtIndexPath crashing intermittently

I have an app with about 30 active users and 500+ registered users and this issue is only happening with one person who is on 9.2 using an iPhone 6. I can see from crash reports she's had over 60 crashes and she has said that the problem is OK…
user2363025
  • 6,365
  • 19
  • 48
  • 89
0
votes
1 answer

Cannot call value of non-function type 'CGFloat' with the alpha property

I am debugging a dropdown menu I converted from Objective-C. In it, I have this function: func showMenu() { self.menu.hidden = false self.menu.translatesAutoresizingMaskIntoConstraints = true …
Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92
0
votes
1 answer

Remove zeros from CGFloat

I have a CGFloat which I am trying to round to 1 decimal place. Using the below code, the CGFloat is rounded to 3.700000, according to NSLog: averageRating = floorf(averageRating * 10.0f + 0.5) / 10.0f; However, for my code to work, which depends…
Isaac A
  • 361
  • 2
  • 24
0
votes
3 answers

Binary Operator '>= & <=' cannot be applied to operands of type CGFloat and Int In Swift

I'm getting two errors. When I use the <= and >=, it gives me the errors: Binary Operator '>= & <=' cannot be applied to operands of type CGFloat and Int override func touchesMoved(touches: Set, withEvent event: UIEvent) { var…
Josh Schlabach
  • 401
  • 5
  • 17
0
votes
1 answer

How to determine correct CGFloat values for desired UIImage Crop iOS 8.4

Currently I am cropping the UIImage received from my UIImagePickerController with this method: - (UIImage *)imageByCroppingImage:(UIImage *)image toSize:(CGSize)size { double refWidth = CGImageGetWidth(image.CGImage); double refHeight =…
Chisx
  • 1,976
  • 4
  • 25
  • 53
0
votes
1 answer

What is the purpose of CGFloat

What makes CGFloat different from a standard float, and why is the CG version needed when working with iOS UI? One thing that bothers me about iOS development is there are a lot of prefixes and it is often unclear what purpose they serve. For…
johncorser
  • 9,262
  • 17
  • 57
  • 102
0
votes
1 answer

Swift Cannot invoke '+' with an argument list of type '($T10, CGFloat)'

I am a beginner in Swift. I have this error Cannot invoke '+' with an argument list of type '($T10, CGFloat)' func loadBackground(key: NSString, width:CGFloat, height:CGFloat) -> UIImage!{ var imageName = key + "_" + width + "_" + height return…
ben77650
  • 39
  • 8
0
votes
1 answer

CGFloat in Array Swift

i have a question about array in Swift. if i have variables like this : var name = [“cafe A”, “Cafe B”] var image = [“cafeaimg.jpg”, “cafebimg.jpg”] var fav = [false, false] i’ll write a class like this : class cafe { var name:String = “” …
hermeneutic
  • 45
  • 2
  • 9
0
votes
2 answers

Incompatible pointer types passing regardless of type?

So I have the following code and on the line that is const double colorMasking[6] right now it is a double but if i clean and build it says Incompatible pointer types passing double should be float. Then however if I change it to float the error…
CMOS
  • 2,727
  • 8
  • 47
  • 83
0
votes
2 answers

CGFloat division crash

I have this code: CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; NSLog([NSString stringWithFormat:@"\n%g pixel \n=======================================",screenWidth]); CGFloat…
samitarmum
  • 83
  • 8
0
votes
1 answer

Unable to Subtract CGFloats

I'm trying to incorporate code from the Keyboard Management documentation produced by Apple into my app. So far I have been able to parse the Objective-C into Swift, but there is one line that I'm having problems with. Here it is in context (the…
Blake Morgan
  • 767
  • 1
  • 7
  • 25