kev
kev

Reputation: 1115

Using Partial Points When Specifying Positions In iOS (Using CGPoint)

I am in the process of converting a UI from Sketch to iOS.

This is a highly unconventional UI, and also all the coordinates I work with are floating point.

CGPoint is a float, and so should have no issues handing floating point coordinates. However, I'd like to know if it is a good practice to use floating point coordinates?

(Intuitively, it'd be better for iOS to handle to conversion of partial points when rendering the UI (because then iOS would know if the user is on a 2x, 3x or Xx interface).)

Upvotes: 2

Views: 51

Answers (1)

Zaid Amir
Zaid Amir

Reputation: 4775

Like CGFloat, CGPoint is a data type, it is not bound to the UI as it is a structure that can be used widely in different applications.

When setting the position of a control or view, you are setting it in pixels. Pixels cannot be divided, it is the smallest unit and there are no pixel fractions.

You can set your position with a floating point but it will always get rounded to the nearest integer.

Upvotes: 1

Related Questions