Member-only story
The Coordinate System: iOS and Swift
The view coordinate system is really important
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- This article has been written in the Playground displaying a UIViewController, although you could do the same in a Single View Application
The View coordinate system
The Units and structs used
CGFloat: A floating point number used for graphics
CGPoint: A C struct containing two CGFloats
CGRect: A C struct with an origin and a size (both of which are representated as a CGSize). Can be initialised with CGRect(origin:, size:)
or CGRect(x: 0, y: , width: , height: )
. The origin is represented as a CGPoint.
CGSize: A C struct with a width and height.
The origin
The origin of any particular view is in the upper-left hand corner

That is, the origin could be represented by a let origin = CGPoint(x: 0, y: 0)
(which is actually the origin shown in the…