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
1
vote
3 answers

Why CGFloat has CG prefix not NS prefix?

I have searched about CGFloat, and i found that it is just a typedef just like NSInteger and NSUInteger. But I want to know why it has CG prefix i.e. Core Graphics.
chirag sanghvi
  • 652
  • 6
  • 8
1
vote
1 answer

How to get a random CGFloat for a constraint?

I'm trying to randomize a leading constraint for a button in swift. To activate this I am selecting a button. When I select the button for the first time, it works well, but all the times after this, it shows a lot of errors in the NSLog. Here's the…
Anton O.
  • 653
  • 7
  • 27
1
vote
2 answers

sizeof() gives an error for array argument

Face an error while converting old Objective C code in swift, which is not resolved after trying all other solutions. Objective C: CGPoint graphPoint[] = { {0.0, 0.0}, {0.0, 20.0}, {20.0, 20.0}, {10.0, 0.0} }; CGFloat radius = 0.0; for (int i = 0; i…
Kampai
  • 22,848
  • 21
  • 95
  • 95
1
vote
2 answers

Swift ScrollView - contentSize can't take a variable Int

Trying to set a scrollView's contentSize and I've run across this issue (Xcode 6.4)... Both of these work perfectly: scrollView.contentSize = CGSize(width:self.view.frame.width, height:1000) scrollView.contentSize =…
RanLearns
  • 4,086
  • 5
  • 44
  • 81
1
vote
2 answers

Wrapper for CGFloat Error

In my CGFloat wrapper Im getting an error Returning CGFloat (aka Double) from a function result type CGfloat aka double take the address with & +(CGFloat*)pointData; // +(CGFloat *)pointData{ NSInteger savedInt = [[NSUserDefaults…
JSA986
  • 5,870
  • 9
  • 45
  • 91
1
vote
0 answers

Unbounded array of CGfloat

I am trying to create an unbounded array in swift. I have found examples of assigning unbounded arrays of Ints and basic Floats, but I am seeing issues when I try to cast the array as an array of CGFloats. The snipet below has an array called…
Rich Maes
  • 1,204
  • 1
  • 12
  • 29
1
vote
1 answer

Using fabsf on CGFloats shows a warning

I'm trying to get the absolute value of a CGFloat parameter but I'm getting the following warning: Absolute value function 'fabsf' given an argument of type 'CGFloat' (aka 'double') but has parameter of type 'float' which may cause truncation of…
YogevSitton
  • 10,068
  • 11
  • 62
  • 95
1
vote
1 answer

On which Apple hardware/OS is CGFloat 32 bit and on which is it 64 bit?

In some cases it can be important to select the correct floating point type for your application, and it seems that on ios/osx you are pushed in the direction of using CGFloat. CGFloat is meant to be the native floating point type, but I can't find…
rghome
  • 8,529
  • 8
  • 43
  • 62
1
vote
2 answers

"'CGFloat' is not convertible to 'UInt8'" - CGFloat wrapping issue

label.position = CGPointMake(self.size.width*0.125, self.size.height-CGFloat(0.15)*self.size.height*_activeEnemiesArray.count) I get an error pointing to self.size.width that says 'CGFloat' is not convertible to 'Double'. This makes sense,…
Christian Ayscue
  • 641
  • 1
  • 7
  • 22
1
vote
3 answers

Objective-C: Separate number right/left of decimal

I am trying to separate the left and right numbers from a float so I can turn each into a string. So for example, 5.11, I need to be able to turn 5 into a string, and 11 into another string. // from float: 5.11 NSString * leftNumber =…
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
1
vote
1 answer

iOS const CGFloat error: linker command failed

I am trying to add constant const CGFloat in Header.h file: #import #ifndef Sample_Header_h #define Sample_Header_h const CGFloat myCustomCoordinateY = 430.0f; #endif and I always run into error: ld: 6 duplicate symbols for…
Jacob Jones
  • 501
  • 2
  • 6
  • 22
1
vote
4 answers

Swift function that takes in array giving error: '@lvalue $T24' is not identical to 'CGFloat'

So I'm writing a lowpass accelerometer function to moderate the jitters of the accelerometer. I have a CGFloat array to represent the data and i want to damp it with this function: // Damps the gittery motion with a lowpass filter. func…
DShaar
  • 155
  • 2
  • 6
1
vote
1 answer

Multiply/Divide Floats Produce Double?

In Objective-C (or C), if I do CGFloat distance = 215; CGFloat velocity = 20; NSTimeInterval time = distance / velocity; is that correct? Or, should I cast either distance or velocity to NSTimeInterval? Note, in iOS 7.0: #if defined(__LP64__) &&…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
1
vote
1 answer

How to convert to pixels to CGFloat?

I have an image with width as '50px' and height as '40px' in my Webpage. Now i want to display the image with same dimensions in UIImageView. How can i convert the pixels into CGFloat? Thanks for your answers.
Kirubachari
  • 688
  • 11
  • 27
1
vote
2 answers

Incompatible block pointer types initializing 'CGFloat (^__strong)(CGFloat)' with an expression of type 'double (^)(CGFloat)'

I'm trying to create a block variable that takes a CGFloat argument and returns a CGFloat. CGFloat (^debt)(CGFloat) = ^(CGFloat myFloat) { return myFloat * 444563.4004; }; What is wrong with this definition? Why am I getting this warning?
zakdances
  • 22,285
  • 32
  • 102
  • 173