ํฐ์คํ ๋ฆฌ ๋ทฐ
AutoLayout ์ด๋?
์ ์ฝ ์กฐ๊ฑด์ ๊ธฐ๋ฐ์ผ๋ก ๋์ ์ผ๋ก ํฌ๊ธฐ์ ์์น๋ฅผ ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ
- ๋๋ฐ์ด์ค์ view ์ฌ์ด์ฆ์ ๋ฐ๋ผ ์ ์ฝ์กฐ๊ฑด์ ๋ง๊ฒ ์์น์ ์ฌ์ด์ฆ๋ฅผ ๋์ ์ผ๋ก ์กฐ์
- ์ด๋ ๋๋ฐ์ด์ค์์๋ ์ง ๊ฐ์ ๋ ์ด์์์ ๊ฐ์ง๋๋ก ํฉ๋๋ค.
View์ ์์ฑ
1. ์์น ์์ฑ - CenterX, Leading, Trailing, CenterY, Top, Bottom
2. ํฌ๊ธฐ ์์ฑ - Width, Height
- ๊ณ ์ ๋์ด ์๋ ์ ๋๊ฐ์ด ์๋, ์กฐ๊ฑด(contraints)์ ์ค์
private func layout() {
view.addSubview(firstView)
view.addSubview(secondView)
view.addSubview(thirdView)
view.addSubview(fourthView)
view.addSubview(fifthView)
// 1
firstView.snp.makeConstraints { make in
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(149)
make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide).inset(70)
make.height.equalTo(152)
}
// 2
secondView.snp.makeConstraints { make in
make.top.equalTo(firstView.snp.bottom).offset(23)
make.leading.equalTo(self.view.safeAreaLayoutGuide).inset(70)
make.height.equalTo(152)
make.width.equalTo(115)
}
// 3
thirdView.snp.makeConstraints { make in
make.top.equalTo(firstView.snp.bottom).offset(23)
make.leading.equalTo(secondView.snp.trailing).offset(5)
make.trailing.equalTo(self.view.safeAreaLayoutGuide).inset(70)
make.height.equalTo(32)
}
// 4
fourthView.snp.makeConstraints { make in
make.top.equalTo(thirdView.snp.bottom).offset(5)
make.leading.equalTo(secondView.snp.trailing).offset(5)
make.trailing.equalTo(self.view.safeAreaLayoutGuide).inset(70)
make.height.equalTo(32)
}
// 5
fifthView.snp.makeConstraints { make in
make.top.equalTo(fourthView.snp.bottom).offset(5)
make.leading.equalTo(secondView.snp.trailing).offset(5)
make.trailing.equalTo(self.view.safeAreaLayoutGuide).inset(70)
make.height.equalTo(76)
}
}
- ์ ์ฌ์ง๊ณผ ๊ฐ์ ๋ทฐ๋ฅผ ๋ง๋ค๊ธฐ ์ํด์ ์์ฑํ ์ฝ๋
Safe Area
- ์์ ํ๊ฒ ์ปจํ ์ธ ๋ฅผ ํ์ํ ์ ์๋ ์์ญ
- ํ๋ฉด์ ๊ฐ๋ ์ฑ์์ผ ํ์ง ์๋ ์ด์ Safe Area๋ฅผ ์ฌ์ฉํด ๋ ์ด์์ ์ก๋ ๊ฒ์ด ๋ณดํธ์
UIScrollView
- ์์ฒด์ ์ผ๋ก ๊ฐ์ง๋ ์ปจํ ์ธ ์ ์คํฌ๋กค ๋ฐ ํ๋/์ถ์๋ฅผ ๊ฐ๋ฅํ๊ฒ ํด์ฃผ๋ ๋ทฐ
- ์ํ๋ฟ๋ง ์๋๋ผ ์ข์ฐ๋ก๋ ๊ฐ๋ฅ
- ์ปจํ ์ธ ์ ๊ธธ์ด๊ฐ ํ๋ฉด๋ณด๋ค ๊ธธ๊ฑฐ๋ ํด ๊ฒฝ์ฐ ์คํฌ๋กค ๋์ ๊ฐ๋ฅ, ์ปจํ ์ธ ๊ธธ์ด๊ฐ ์์ ๋๋ ๋์ํ์ง ์์
AutoLayout in ScrollView
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.addSubview(containerView)
containerView.addSubview(firstView)
containerView.addSubview(secondView)
containerView.addSubview(thirdView)
containerView.snp.makeConstraints { make in
make.edges.equalTo(self.view.safeAreaLayoutGuide) // scroll view ๋ค ์์๋ ๋ฐ์ฐฉ
}
firstView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide)
make.height.equalTo(337)
}
secondView.snp.makeConstraints { make in
make.top.equalTo(firstView.snp.bottom).offset(45)
make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide)
make.height.equalTo(337)
}
thirdView.snp.makeConstraints { make in
make.top.equalTo(secondView.snp.bottom).offset(45)
make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide)
make.height.equalTo(337)
make.bottom.equalToSuperview().offset(-45)
}
}
- ์๋ฅผ ๊ตฌํํ๊ธฐ ์ํ ์ ์ฒด ์ฝ๋
containerView.snp.makeConstraints { make in
make.edges.equalTo(self.view.safeAreaLayoutGuide) // scroll view ๋ค ์์๋ ๋ฐ์ฐฉ
}
- ScrollView๋ฅผ safe area ์ ์ฒด์ ๋ฐ์ฐฉ
thirdView.snp.makeConstraints { make in
make.top.equalTo(secondView.snp.bottom).offset(45)
make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide) // ?
make.height.equalTo(337)
make.bottom.equalToSuperview().offset(-45) // ํ๋จ ์ ์ฝ
}
- leading๊ณผ trailing์ ์คํฌ๋กค๋ทฐ๊ฐ ์๋ safe area์ ๋ง์ถ๋ ์ด์ ?
- ๋ง์ง๋ง ์ปดํฌ๋ํธ๋ ์คํฌ๋กค๋ทฐ์์ ํ๋จ ์ ์ฝ์ ๊ผญ ์ฃผ์ด์ผ ํจ
'๐ iOS > ๐ Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] DatePicker ๋ง๋ค๊ธฐ (0) | 2023.01.20 |
---|---|
[Swift] navigation stack ์์ด์ง ์๊ณ ์๋กญ๊ฒ ๋ทฐ ์ ํํ๋ ๋ฐฉ๋ฒ (0) | 2022.10.12 |
[Swift] UILabel์ ๋ ์ค ์ด์ ์ ๋ ฅํ๋ ๋ฒ (0) | 2022.10.05 |
- Linux
- ๊ธฐ๊ณํ์ต
- MySQL
- ๋ฐฑ์ค
- ๋ฆฌ๋ ์ค
- C
- PHP
- ํ์ผ ์ ์ถ๋ ฅ
- Apache
- react-scripts
- GIT
- SpringBoot
- machine learning
- ๋ฒํผ
- C++
- Programming
- ์ค์น
- Annotation
- ํ๋ก์ธ์ค
- SWiFT
- ์๊ณ ๋ฆฌ์ฆ
- ์ค๋ฅ
- bitnami
- error
- react
- Baekjoon
- ํ๋ก๊ทธ๋๋ฐ
- ๋ค์คํ๋ก์ธ์ค
- ๋จธ์ ๋ฌ๋
- 9086๋ฒ
- Total
- Today
- Yesterday