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

<6주차> Intrinsic Size에 대해서 설명하시오. #28

Closed
namsoo5 opened this issue Dec 15, 2020 · 7 comments
Closed

<6주차> Intrinsic Size에 대해서 설명하시오. #28

namsoo5 opened this issue Dec 15, 2020 · 7 comments

Comments

@namsoo5
Copy link
Collaborator

namsoo5 commented Dec 15, 2020

No description provided.

@namsoo5
Copy link
Collaborator Author

namsoo5 commented Dec 17, 2020

콘텐츠에 따라 뷰가 자연스럽게 차지하는 크기
frame과 독립적이다
일부뷰는 내부 콘텐츠 크기를 가지고 있음
ex) UILabel, UISwitch, 이미지가 들어있는 UIImageView등

@namsoo5 namsoo5 added the 남수 label Dec 17, 2020
@khyunjiee
Copy link
Member

Intrinsic Size

컨텐츠 고유의 사이즈
대부분의 뷰는 고유의 콘텐츠 사이즈를 가진다.
즉, 뷰가 콘텐츠가 이상적인 상태로 나타내기 위해 필요한 공간의 양
ex. UILabel의 고유 크기는 글꼴 + 텍스트 크기

@choidam
Copy link
Member

choidam commented Dec 18, 2020

intrinsicContentSize

Content 에 따라 가지는 고유한 크기를 의미합니다.

  • UIView : Intrinisc content size 없음
  • Slider: width 만 Intrinisc content size 가짐
  • Label, Button, Switch, TextField : height, width Intrinisc content size 모두 가짐
  • TextView, ImageView : content 에 따라 값이 달라짐

@choidam choidam added the label Dec 18, 2020
@iJoom
Copy link
Collaborator

iJoom commented Dec 18, 2020

View가 가져야할 본연의 독립적 크기 (콘텐츠가 좋게 나올 적당한 크기가 이정도이다~)

  • 앞서 공부한, contentHugging과도 연관이 있음
  • Label 같은경우 우리가 사용하는 폰트에 맞춰 Intrinsic Size가 결정되어짐 (폰트마다 진한게 있고 얇은게 있어서 size가 조금씩 다름)

@iJoom iJoom added the 인준 label Dec 18, 2020
@5anniversary
Copy link
Collaborator

Intrinsic Content Size

view 자체의 속성을 고려해 받는 view자체에서 받는 view의 고유한 크기~

우리가 기본적으로 사용하는 autolayout에서 UILabel의 경우에 xy좌표면 잡아줘도 알아서 잘 생성되는것을 생각하시면 된다!!

@dongminyoon
Copy link
Collaborator

콘텐츠가 가지는 고유사이즈이다.
UILabel, UIImagedView, UIButton들이 자동으로 내용물에 맞춰 크기가 조정되는 것은 이 사이즈 때문이다.

UIView는 고유의 Intrinsic ContentSize를 가지지 않는다.

@elesahich
Copy link
Collaborator

elesahich commented Dec 18, 2020

UIView가 가진 프로퍼티. IntrinsicContentSize.

UIView contentView의 크기를 계산한 것. 그리고 당연히 해당 뷰의 frame과는 독립적임니다. (frame != contentSize니까).
그...또 CustomView를 만들다가 intrinsicSize를 이용해서 구현했는데 잘 되었습니다..
방법이 굉장히 야매같지만 상황과 코드는 다음과 같사옵니다

스크린샷 2020-12-18 오후 5 31 04

스크린샷 2020-12-18 오후 5 31 10

사진같이 너무나 돌려써야하는게 당연...한....AlertView가 있습니다.... 얘는 그런데 메시지의 줄 수에 따라서
height가 늘어나야 되었습니다. 1줄 - 2줄 - 3줄. 다행히도 메시지 라벨 height는 달라지지 않는답니다.

그래서... 다른 오토레이아웃은 미리 잡아두고, 함수가 이 AlertView를 호출하는 그 시점요

    func showAlertView(
                       title: String,
                       grantMessage: String,
                       denyMessage: String = "",
                       okAction: PopupDialogButtonAction? = nil) {


// 그럼 이제 여기에서 title에다가 집어넣을거에요
titleLabel.text = title
let titlelabelLineCount = titleLabel.intrinsicContentSize.height / 24  // 24는 라인 한줄의 height
alertView.heightAnchor.constraint(equalToConstant: 170 + 24 * titlelabelLineCount).isActive = true
        
}

위 코드가 동작하려면 intrinsicContentSize는 코드가 실행됨과 동시에 값을 가져야 합니다
(text가 대입되는 순간 intrincsicSize를 가져야 되니까)
다행히 동작하는데...넘 야매같다. 잘못 동작해서 바꾸게 된다면 contentSize를 옵저빙하겟어요

결론 : contentSize는 값이 대입되는 순간 계산이 되는게 아닐까.....하는.....생각이고 그렇습니다

또,,, tableView랑 CollectionView가 SelfSizing하는 것도 intrinsicSize가 개입한다고 함니다. 가끔 잘 안되자나요?
그것은 오토레이아웃 잘 못잡은거다. cell이 나의 intrinsic Size를 계산하지 못했다. 이렇게 생각하시면 좋겠습니다.

@elesahich elesahich added the 승호 승호 label Dec 18, 2020
@namsoo5 namsoo5 closed this as completed Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants