새소식

iOS/Swift

[Swift] frame vs bounds

  • -

Frame과 bounds에 대해 알아보기 전 CGPoint, CGSize, CGRect에 대해 알아야 한다.

 

CGPoint : 2차원 좌표계의 점을 포함하는 Struct

 

CGPoint | Apple Developer Documentation

A structure that contains a point in a two-dimensional coordinate system.

developer.apple.com

 

CGSize : widthheight의 값

 

CGSize | Apple Developer Documentation

A structure that contains width and height values.

developer.apple.com

 

CGRect : 사각형(Rectangle)의 위치와 크기를 포함하는 Struct

- CGRect의 요소 

  • origin(CGRect)
  • size(CGSize)
 

CGRect | Apple Developer Documentation

A structure that contains the location and dimensions of a rectangle.

developer.apple.com

 


Frame : SuperView(상위 뷰)의 좌표 시스템 안에 View의 위치와 크기를 나타냄

  • UIView의 위치나 크기를 설정하는 경우에 사용
 

frame | Apple Developer Documentation

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

developer.apple.com

 

Bounds : View의 위치나 크기를 자신만의 좌표 시스템 안에서 나타냄

  • View 내부에 그림을 그릴 때 (draw Rect)
  • transformation 후 View의 크기를 알고 싶을 때
  • 하위 View를 정렬하는 것과 같이 내부적으로 변경하는 경우
 

bounds | Apple Developer Documentation

The bounds rectangle, which describes the view’s location and size in its own coordinate system.

developer.apple.com

 

 


출처

 

iOS ) Frame과 Bounds의 차이 (1/2)

안녕하세요 :) Zedd입니다. 지금 다른 글을 쓰고있는데, 쓰면 쓸수록 쓸 주제가 많아집니다...급 이 글을 쓰게 됐어요 XD..아무튼 오늘은 저도 궁금했던 Frame과 Bounds의 차이를 알아볼거에요 :)다음글

zeddios.tistory.com

 

728x90

'iOS > Swift' 카테고리의 다른 글

[Swift] 공식문서 파헤치기 (Array, Set, Dictionary)  (0) 2023.11.11
[Swift] UISceneDelegate  (0) 2023.11.09
[Swift] BackgroundTasks  (0) 2023.09.03
[Swift] Dynamic Library vs Static Library  (0) 2023.08.21
[Swift] Core Data  (0) 2023.08.21
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.