Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

자신만의 Custom View를 만들려면 어떻게 해야하는지 설명하시오. #20

Open
dailynj opened this issue Nov 15, 2021 · 4 comments
Labels

Comments

@dailynj
Copy link
Contributor

dailynj commented Nov 15, 2021

No description provided.

@dailynj dailynj added the iOS label Nov 15, 2021
@co3oing
Copy link
Member

co3oing commented Nov 17, 2021

Custom View를 만들기 위해서는 Xib를 이용하거나 UIView를 상속 받는 Class를 생성하면 됩니다.

@dailynj
Copy link
Contributor Author

dailynj commented Nov 17, 2021

자신만의 Custom View 를 만든기 위해서는 두가지 방법이 있습니다. 첫번째는 Xib를 이용하는 방법으로, UIView 파일을 만들고 드래그로 끌어다가 놓고 UIView에 클래스이름을 지정해주면 됩니다. 이 방법을 사용할 때는 required init 를 꼭 구현해야한다는 특징이 있습니다.

두번쨰는 100% 코드로만 작성하는 방법으로, init(frame:)함수를 구현해야하고 뷰 컨트롤러에서 인스턴스를 만들고 addSubview를 통해 뷰를 추가해주면 됩니다.

@inuinseoul
Copy link
Collaborator

inuinseoul commented Nov 17, 2021

가장 기본적인 방법으로는 UIView를 상속받아 class를 생성하는 방법이 있습니다. 이 때 override init(frame: CGRect)와 required init?(coder: NSCoder)는 필수적으로 작성해야하는데, 하나는 코드로 View를 생성할 때 사용되는 생성자이고 하나는 스토리보드에서 View를 연결할 때 사용되는 생성자입니다.

다른 방법으로는 xib 파일을 통해 생성하는 방법이 있습니다. xib파일을 생성하고 xib에서 view를 디자인한다음 이를 불러와 사용하는 것입니다.

@duyeonnn
Copy link
Collaborator

첫째는 xib 파일을 만들어 Storyboard처럼 만들 수 있습니다. 이때 별도 UIView를 상속받는 class를 생성해 xib파일과 커스텀 클래스를 연결해 줘야 합니다.

둘째는 UIView를 상속받는 Custom View class를 만들고 모든 컴포넌트를 코드로 구성하는 방식이 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants