-
[iOS] ์ธ์คํ๊ทธ๋จ ํด๋ก ์ฝ๋ฉ์ ํด๋ณด์!(1) - ๋ก๊ทธ์ธ, ํ์๊ฐ์ ํ๋ฉดiOS/project 2022. 9. 23. 23:33
๐ ๋ชฉํ
- storyboard, autolayout๊ณผ ์นํด์ง๊ธฐ
- ๋ฒํผ์ ๋๋ ์ ๋ ๋์ด๊ฐ๋ ํ๋ฉด ๊ตฌํํ๊ธฐ๊ฒฐ๊ณผ๋ฌผ
storyboard๋ก object ์์ฑํ๊ธฐ
์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๋ ๊ฒ์ ๋ณ๋ก ์ด๋ ต์ง ์์ผ๋ฏ๋ก ๊ฟํ๋ง ๊ธฐ๋กํด๋๋ค
์ค๋ธ์ ํธ๋ฅผ ์ ํํ๊ณ , ctrl์ ๋๋ฌ ๋ค๋ฅธ ์ค๋ธ์ ํธ์ ๊ฐ์ ธ๋ค๋๋ฉด constraint๋ฅผ ์ค์ ํ ์ ์๋ ํ์ ์ด ๋ ์ ํจ์ฌ ํธ๋ฆฌํ๋ค!
ํ์ด์ค๋ถ์ผ๋ก ๋ก๊ทธ์ธ ๋ฒํผ์ ๋ง๋ค ๋, ๋ฒํผ ์์ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ก ๊ตฌํํ์ง ์๊ณ ๋ฒํผ์ ์์ฑ inspector์์ ๊ฐ์ด ์ค์ ํด์ค ์ ์๋ค
Button Action ๊ตฌํํ๊ธฐ
@IBAction func emailTextFieldEditingChanged(_ sender: UITextField) { let text = sender.text ?? " " //์ต์ ๋ self.email = text } @IBAction func passwordTextFieldEditingChanged(_ sender: UITextField) { let text = sender.text ?? " " self.password = text }
๋จผ์ ์์ด๋, ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅ๋ฐ์ ๊ฐ์ ์ ์ฅํ๊ธฐ ์ํด textField์ ์ก์ ์ ๊ตฌํํ๋ค.
class LoginViewController: UIViewController { // ์ ๋ ฅ๋ฐ์ ๊ฐ์ ์ ์ฅํ ๋ฉค๋ฒ ๋ณ์ var email = String() var password = String() override func viewDidLoad() { super.viewDidLoad() }
๊ทธ ๋ค์, ์ ๋ ฅ๋ฐ์ ๊ฐ์ ์ ์ฅํ ๋ฉค๋ฒ ๋ณ์๋ฅผ ์ ์ธํด์ค๋ค.
์ฝ์์ฐฝ์ ํตํด ์์ด๋, ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ ๊ฒฝ์ฐ ๊ฐ์ด ์ ์ฅ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
๊ฐ์ ํ๊ธฐ ๋ฒํผ ๋๋ ์ ๋ ํ๋ฉด ์ ํ
๐ ํ๋ฉด ์ ํ ๋ก์ง
์คํ ๋ฆฌ๋ณด๋ ์์ฑ -> ๋ทฐ์ปจํธ๋กค๋ฌ ์์ฑ -> ํ๋ฉด ์ ํ ๋ฉ์๋ ์ด์ฉํด์ ํ๋ฉด ์ ํ1. ์คํ ๋ฆฌ๋ณด๋ ์์ฑ
- let storyboard = UIStoryboard(name: "Main", bundle: nil)
- Objects - view controller๋ก main.storyboard์ ์๋ก์ด ๋ทฐ ์ปจํธ๋กค๋ฌ๋ฅผ ์์ฑํด์ค๋ค.
- new file - cocoa touch class - RegisterViewController๋ฅผ ์์ฑํด์ค๋ค.
- storyboard์ ๊ฐ์ identifyt inspector - Class์ RegisterViewController๋ก ์ฐ๊ฒฐํด์ค๋ค!
2. ๋ทฐ์ปจํธ๋กค๋ฌ ์์ฑ
let registerViewController = storyboard.instantiateViewController(withIdentifier: "RegisterVC") as! RegisterViewController
3. ํ๋ฉด ์ ํ ๋ฉ์๋
1) self.present(registerViewController, animated: true, completion: nil)
-> ์๋์์ ์๋ก ํ์ ๊ฐ์ด ๋ํ๋๋ค
2) Navigation Controller ์ด์ฉ
ํด๋น ๋ฒํผ์ ํตํด Navigation Controller๋ฅผ ์์ฑํ ๋ค ์ฝ๋๋ฅผ ์์ฑํ๋ค
self.navigationController?.pushViewController(registerViewController, animated: true)
'iOS > project' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] ์ธ์คํ๊ทธ๋จ ํด๋ก ์ฝ๋ฉ์ ํด๋ณด์!(3) - ๋ฒํผ ์์ฑ&๊พธ๋ฏธ๊ธฐ (1) 2022.10.10 [iOS] ์ธ์คํ๊ทธ๋จ ํด๋ก ์ฝ๋ฉ์ ํด๋ณด์!(2) - ํ์๊ฐ์ ์ก์ ์ฐ๊ฒฐ (0) 2022.10.03 [Swift] Dice game์ Auto layout ์ถ๊ฐํ๊ธฐ (0) 2022.08.15 [Swift] Dice game! ์ฃผ์ฌ์๋ฅผ ๊ตด๋ ค๋ณด์ธ์ (0) 2022.08.04 [Swift] Hi xcode! ๊ฐ๋จํ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ํด๋ณด๊ธฐ (0) 2022.07.27