Created
November 2, 2023 07:21
-
-
Save f2janyway/3edec14660ff544d850b6b00259624ae to your computer and use it in GitHub Desktop.
UIStackView 자리 배치 및 스트래칭
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| stackview:[label1, <-label2->, label3] ex | |
| */ | |
| let label1 = UILabel() | |
| label1.text = "label1" | |
| label1.backgroundColor = .brown | |
| let label2 = UILabel() | |
| label2.backgroundColor = .lightGray | |
| label2.text = "label2" | |
| //label2.text = "label2label2label2label2label2label2label2label2label2label2label2label2 label2" | |
| label2.numberOfLines = 0 | |
| label2.numberOfLines = 0 | |
| let label3 = UILabel() | |
| label3.text = "label3" | |
| label3.backgroundColor = .green | |
| let stackView = UIStackView(arrangedSubviews: [label1, label2, label3]) | |
| stackView.alignment = .top | |
| stackView.backgroundColor = .magenta | |
| stackView.axis = .horizontal | |
| //만약 이걸 사용하려면 width 값을 1이 아닌 적정한 값을 사용하기 | |
| // label1.snp.makeConstraints { make in | |
| // make.width.equalTo(1).priority(2) | |
| // } | |
| //label2만 제약을 적용해서 늘어나게함 | |
| label2.snp.remakeConstraints { make in | |
| make.width.equalTo(1).priority(1) | |
| } | |
| // label3.snp.makeConstraints { make in | |
| // make.width.equalTo(1).priority(2) | |
| // } | |
| // Set content hugging priority | |
| //이걸 적용해야 label2 내용이 많이지면 눌리지않음 | |
| label1.setContentHuggingPriority(.defaultHigh, for: .horizontal) | |
| // label2.setContentHuggingPriority(.defaultLow, for: .horizontal) | |
| label3.setContentHuggingPriority(.defaultHigh, for: .horizontal) | |
| // label1.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | |
| // label3.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment