개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.03.17 04:40

UISize::of 관련 질문

  • WebSocket광 3시간 전 2025.03.17 04:40 새글
  • 2
    1
저는 Swift에서 UIView의 크기를 얻어내는 방법에 대해 궁금합니다.
UIView의 크기를 얻어내는 방법은 UISize::of를 사용하는 것처럼 보이는데, 정확한 방법을 알려주세요.
UISize::of는 어떤 클래스의 메서드인지 알려주세요.

    댓글목록

    profile_image
    나우호스팅  3시간 전



    Swift에서 UIView의 크기를 얻어내는 방법은 `bounds` 프로퍼티를 사용하는 것입니다.

    #hostingforum.kr
    swift
    
    let view = UIView()
    
    let size = view.bounds.size
    
    print(size.width, size.height)
    
    


    또는 `frame` 프로퍼티를 사용하는 방법도 있습니다.

    #hostingforum.kr
    swift
    
    let view = UIView()
    
    let size = view.frame.size
    
    print(size.width, size.height)
    
    


    `UISize::of`는 Objective-C의 `UIEdgeInsetsMake` 함수와 유사한 `UIEdgeInsets` 클래스의 `init` 메서드에 사용되는 이름입니다.

    #hostingforum.kr
    swift
    
    let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    
    


    이 메서드는 `UIEdgeInsets` 클래스의 인스턴스를 생성하는 데 사용됩니다.

    Swift에서 `UIEdgeInsets` 클래스는 `UIEdgeInsets` struct로 대체되었습니다.

    #hostingforum.kr
    swift
    
    let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    
    


    이 struct는 `top`, `left`, `bottom`, `right` 프로퍼티를 사용하여 인스턴스를 생성할 수 있습니다.

    #hostingforum.kr
    swift
    
    let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    
    print(insets.top, insets.left, insets.bottom, insets.right)
    
    


    `UIEdgeInsets` struct는 `width` 프로퍼티를 사용하여 두 가로边缘의 합을 계산할 수 있습니다.

    #hostingforum.kr
    swift
    
    let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    
    print(insets.width)
    
    


    `UIEdgeInsets` struct는 `height` 프로퍼티를 사용하여 두 세로边缘의 합을 계산할 수 있습니다.

    #hostingforum.kr
    swift
    
    let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    
    print(insets.height)
    
    

    2025-03-17 04:41

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 4,032건 / 1 페이지

검색

게시물 검색