Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert int to CGFloat

Any idea on how to convert an int to CGFloat in Objective-C?

like image 701
Shoaibi Avatar asked Jun 28 '09 20:06

Shoaibi


2 Answers

In the past casting a CGFloat value using the () syntax has worked fine for me. CGFloat is just defined as "typedef float CGFloat;" so you go about casting it the same way you would a float:

CGFloat f = (CGFloat)intVal; 

or, if your value is a constant:

CGFloat f = 1.10; 
like image 122
Ben Gotow Avatar answered Oct 12 '22 23:10

Ben Gotow


i was searching in how to do the same in swift and i find the question in first result (high ranked) so i will post the answer if had found in case someone was lucky like me :)

let myCGFloat = CGFloat(myFloat) 
like image 34
Amr Angry Avatar answered Oct 12 '22 23:10

Amr Angry