์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- MVVM
- arkit
- BFS
- SwiftUI
- SnapKit
- node.js
- designpattern
- Swfit
- combine
- rxcocoa
- ios
- ํ๋ก๊ทธ๋๋จธ์ค
- Kuring
- UIKit
- Lv2
- realm
- visionOS
- BOJ
- swift
- TCA
- CollectionView
- ๋ฐฑ์ค
- RxSwift
- ํจ์คํธ์บ ํผ์ค
- tableView
- Xcode
- raywenderlich
- XCTest
- reactorkit
- Flutter
- Today
- Total
lgvv98
iOS SnapKit 01 | leading & trailing ๋ณธ๋ฌธ
iOS SnapKit 01 | leading & trailing
๐ฅ ์บ๋ฟ๋งจ 2021. 8. 18. 15:42โ ์ด๋ฒ ์๊ฐ์๋ ๊ฐ์ฅ ๊ธฐ์ด์ ์ธ ๋ถ๋ถ์ ๋ํด์ ์์๋ณผ ์์ ์ด์ผ.
์ค๋ ํท์ ๊ณต๋ถํ ๋๋ ์์ ๋ฅผ ํตํด์ ํ๋ํ๋ ์์๋ณด๋๊ฒ ๋๋ฐฐ๋ก ์ข์ ๊ฒ ๊ฐ์์ ์ด๋ ๊ฒ ์งํํ๊ธฐ๋ก ํ์ด
๋ค์ด๊ฐ๊ธฐ์ ์์...
์ง๊ธ๊น์ง ๋๋ UIStoryboard ์๋ค๊ฐ ๋ฒํผ์ด๋ ๋ ์ด๋ธ๋ค์ ์ฌ๋ ค์ ์ฃผ๋ก ์ฌ์ฉํ์๋๋ฐ, ์ด ๋ฐฉ๋ฒ์ ์น๋ช ์ ์ธ ๋จ์ ์ ์๊ฒ๋์ด์ ์ฝ๋๋ก ์์ฑํ๋ ๋ฒ๋ ์ฌ๊ธฐ์ ๊ณต๋ถํด ๋ณด๋ ค๊ณ ํด.
๋ฌผ๋ก , IBOulet์ ์ด์ฉํด์ snp๋ฅผ ๊ฑธ์ด๋ ๊ฐ๋ฅํด.
๐ก ๋ด๊ฐ ๋๋ ์น๋ช ์ ์ธ ๋จ์
- Storyboard์ ์ฌ๋ ค์ ์์ ์, ์ถํ์ ๋ฃ๋ ์ด๋ฏธ์ง๋ ์์ด์ฝ๋ค์ด ๊ฐ์ฅ ๋ท ๋ถ๋ถ์ผ๋ก ๊ฐ์ผํ๋ฉด, ์คํ ๋ฆฌ ๋ณด๋๋ฅผ ๊ฐ๋ฆฌ๊ฒ ๋์ด์ ๋ถํธํจ์ ์ด๋ํจ.
โ [์ค๋์ ์์ ]
SnapKit์ ํ์ฉํ์ฌ UIButton, UILabel, UITextField๋ฅผ ๋ฐฐ์นํ์ฌ ๋ณด์.
โ [์์ ์ ๊ฒฐ๊ณผ]
โ ์ฝ๋ ๋ฆฌ๋ทฐ
//
// ViewController.swift
// SnapKit_practice
//
// Created by Hamlit Jason on 2021/08/18.
//
import UIKit
import SnapKit
class ViewController: UIViewController {
lazy var box = UIView()
lazy var nameLabel = UILabel()
lazy var nameTextField = UITextField()
lazy var changeButton = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
setUpView()
}
func setUpView() {
self.view.addSubview(self.nameLabel)
self.view.addSubview(self.nameTextField)
self.view.addSubview(self.changeButton)
nameLabel.text = "this is UILabel"
nameTextField.placeholder = "this is UITextField"
changeButton.setTitle("this is UIButton", for: .normal)
nameLabel.backgroundColor = .blue
nameTextField.backgroundColor = .green
changeButton.backgroundColor = .red
self.nameLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(80)
$0.leading.equalToSuperview().offset(24)
$0.trailing.equalToSuperview().offset(-24)
}
self.nameTextField.snp.makeConstraints { // ๋ค์ ๋ ์ด๋ธ์ ๊ธฐ์ค์ผ๋ก ๋ฐฐ์นํ๊ธฐ
$0.top.equalTo(self.nameLabel.snp.bottom).offset(24)
$0.leading.equalTo(self.nameLabel)
$0.trailing.equalTo(self.nameLabel)
//$0.leading.trailing.equalTo(self.nameLabel) ์ด๋ ๊ฒ ์ค์ฌ์ธ ์ ์๋ค.
}
self.changeButton.snp.makeConstraints { make in
make.center.equalToSuperview()
// $0.center.equalToSuperview()
make.size.greaterThanOrEqualTo(nameTextField) // ๊ฐ๊ฑฐ๋ ํฌ๊ฒ
}
}
}
์ฝ๋๋ฅผ ๊ทธ๋ฅ ์ญ ์ฝ์ด๋ณด๋ฉด ํฌ๊ฒ ์ด๋ ค์ด ๋ถ๋ถ์ด ์๋ค.
๋ค๋ง, Button์ ๊ฒฝ์ฐ size๋ฅผ ์ง์ ํด์ฃผ์ง ์์ผ๋ฉด ๋ฒํผ์ ํฌ๊ธฐ๊ฐ ๋ฒํผ์ ๋ด์ฉ์ ๋ง๊ฒ ์กฐ์ ๋๋ฏ๋ก ๊ผญ ์ ์ํ๊ธฐ
๋ํ ํ ์คํธํ๋๋ ๋ค์๋ ์ด๋ธ ์ชฝ์ ๊ฑธ์ด์ค ๋ชจ์ต์ ํ์ธํ ์ ์์ด.
'โ ๏ธ deprecated โ ๏ธ > iOS Third Party' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
iOS SnapKit 04 | iOS tableView๋ฅผ ์ฝ๋๋ก ๊ตฌ์ฑํ๋ ๋ฒ 02 (0) | 2021.08.19 |
---|---|
iOS SnapKit 03 | iOS tableView๋ฅผ ์ฝ๋๋ก ๊ตฌ์ฑํ๋ ๋ฒ 01 (0) | 2021.08.19 |
iOS SnapKit 02 | Then ๋ผ์ด๋ธ๋ฌ๋ฆฌ (0) | 2021.08.18 |
iOS SnapKit ๊ณต์๋ฌธ์๋ก ๊ณต๋ถํ๊ธฐ (0) | 2021.08.18 |
iOS SnapKit ์์ํ๊ธฐ (0) | 2021.08.18 |