CGPoint

A structure that contains a point in a two-dimensional coordinate system. 2차원 좌표에서 한 점을 포함하는 structure

[sample]

import UIKit

class ViewController: UIViewController {

    let myView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.systemBlue
        //view.frame.size = CGSize(width: 400, height: 800)
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        view.addSubview(myView)
        print("mySubViews center: ", myView.center)
    }

}

// mySubViews center:  (0.0, 0.0)

간단한 subView를 만들자.

view의 크기가 정해지지 않았을 경우에 view의 center 값(CGPoint)은 0.0, 0.0 인가 보다.

<aside> 💡 iOS 에서 0,0은 좌 하단이 아닌 좌 상단이다.

</aside>

CGSize

A structure that contains width and height values.

<aside> 💡 Device: iPhone 11, Dimensions (portrait): 414x896 pt (828x1792 px @2x)

</aside>

view.frame.size = CGSize(width: 400, height: 800)

// mySubViews center:  (200.0, 400.0)

이번엔 서브뷰의 프레임의 사이즈를 CGSize를 통해 정해주자.

실행해보면 화면을 거의 채우는 파란색 직사각형을 확인할 수 있다.

CGRect

A structure that contains the location and dimensions of a rectangle. 직사각형의 location과 dimensions을 포함하는 structure

위치와 크기를 갖는 사각형.

그렇기 때문에 CGRect는 CGPoint와 CGSize로 정의할 수 있다.

[sample code]