Any idea on how to convert an int
to CGFloat
in Objective-C?
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;
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)
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