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

[Swift] Self-Sizing CollectionView (동적 width) [2 / 2] #27

Closed
seungchan2 opened this issue May 10, 2022 · 0 comments
Closed

[Swift] Self-Sizing CollectionView (동적 width) [2 / 2] #27

seungchan2 opened this issue May 10, 2022 · 0 comments
Assignees
Labels

Comments

@seungchan2
Copy link
Owner

seungchan2 commented May 10, 2022

이것만 잘 보면 댐 ㅋㅋ ㅈㅅㅈㅅ

일단 이걸 써서 할라면 sectionInset, minimumLineSpacing 등을 잘 잡아주시고 사용하셈

지금부터 설명할 건 태현이 블로그에 잘 나와있어서 ㅋㅋㅋ 좀 카피캣해보겠음

  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        return CGSize(width: timeArray[indexPath.item].size(withAttributes: [NSAttributedString.Key.font : UIFont.font(.pretendardRegular, ofSize: 17)]).width + 20, height: 32)
    }

CGSize

CGSize는 너비와 높이 값을 포함하는 구조체임

스크린샷 2022-05-10 오후 10 59 26

size(withAttributes:)

앞에서 말했듯이 텍스트의 크기만 안다면 셀의 너비를 구할 수 있다했잖슴? 그걸 바꿔주는 메서드임

NSAttributedString

이게 사실 뭐라고 한 줄로 정의내리기 애매한데 해보겠음

문자열의 속성을 지정하거나 접근할 때 사용하는 걸로 앎

마지막으로 + 20은 여백 때문에 줌!

@seungchan2 seungchan2 self-assigned this May 10, 2022
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

1 participant