class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidroad()
// ์ ํ์ด ๋ง๋ค์ด ๋์ ์๋ํจ์.
๋ทฐ๊ฐ ๋ก๋ ๋๋ฉด์ ํจ์ ์์ ์คํ๋ฌธ์ด ์คํ๋จ.
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidroad()
view.backgroundColor = .green
// ํ๋ฉด ๋ท์ปฌ๋ฌ ๋ง๋ค๊ธฐ
}
}
command + shift + l ๋จ์ถํค๋ฅผ ์ด์ฉํ์ฌ label์ ์ฐพ์ ๋ฐ๋ก ๋ง๋๋ ๋ฐฉ๋ฒ๊ณผ
์ฝ๋๋ก label ๋ง๋๋ ๋ฐฉ๋ฒ์ด ์๋ค.
class ViewController: UIViewController {
let label = UILabel()
// uilabel๋ง๋ค๊ธฐ
override func viewDidLoad() {
super.viewDidroad()
view.backgroundColor = .green
view.addSubview(label) //์ด ์ํ๋ ๊ธ์๋ฅผ ์๋ฃ์ด์ค์ ๋ณด์ด์ง ์๋๋ค.
label.text = "yjpotato" //์ด๋๋ ๊ธ์๊ฐ ๋ณด์ด์ง ์๋๋ค. ์ด์ ๋ ์์น๋ฅผ ์์ ์ด์คฌ๊ธฐ ๋๋ฌธ์!
label.frame = CGRect (x: view.frame.midX,
y: view.frame.midY,
width: 200,
height: 100)
label.backgroundColor = .red //label ๋ค์ ์์ ์
ํ๊ธฐ. ์ด๋ ์์น๊ฐ ์ ๊ฐ์ด๋ฐ๊ฐ ์๋๋ค. ๋ค์ ์์น ์ ํด์ฃผ๊ธฐ!
}
}
class ViewController: UIViewController {
let label = UILabel()
// uilabel๋ง๋ค๊ธฐ
override func viewDidLoad() {
super.viewDidroad()
view.backgroundColor = .green
view.addSubview(label)
label.text = "yjpotato"
label.frame = CGRect (x: view.frame.midX - 100,
y: view.frame.midY - 50,
width: 200,
height: 100) // label๋ค์ ๋ฐ์ค๊ฐ ๊ฐ์ด๋ฐ์ ์์ง๋ง ๊ธ์๋ ๊ฐ์ด๋ฐ๊ฐ ์๋๋ค.
label.backgroundColor = .red
label.textAlignment = .center // ๊ธ์๊ฐ ๊ฐ์ด๋ฐ ์๋ค!
}
}
class ViewController: UIViewController {
let label = UILabel()
// uilabel๋ง๋ค๊ธฐ
override func viewDidLoad() {
super.viewDidroad()
view.backgroundColor = .green
view.addSubview(label)
label.text = "yjpotato"
let width: CGFloat = 200 // label๋ค ๋ฐ์ค ๊ฐ์ด๋ฐ ์ ๋ ฌ ์๋ก์ด ๋ฐฉ๋ฒ
let height: CGFloat = 100
label.frame = CGRect (x: view.frame.midX - width / 2,
y: view.frame.midY - height / 2,
width: width,
height: height)
label.backgroundColor = .red
label.textAlignment = .center
}
}
class ViewController: UIViewController {
let button = UIButton(type: .system)
override func viewDidLoad() {
super.viewDidroad()
view.backgroundColor = .green
view.addSubview(button)
button.setTitle("๋ฒํผ", for: .normal) // setTitle์ button์์๋ง ์ฌ์ฉ๊ฐ๋ฅ.
let width: CGFloat = 200
let height: CGFloat = 100
button.frame = CGRect (x: view.frame.midX - width / 2,
y: view.frame.midY - height / 2,
width: width,
height: height)
button.backgroundColor = .red
}
}
class ViewController: UIViewController {
let button = UIButton() // ๋ฒํผ์ด ๋ณด์ด์ง ์์ง๋ง ์์.
override func viewDidLoad() {
super.viewDidroad()
view.addSubview(button)
button.setTitle("๋ฒํผ", for: .normal)
button.setTitleColor(.red, for: .normal)
let width: CGFloat = 200
let height: CGFloat = 100
button.frame = CGRect (x: view.frame.midX - width / 2,
y: view.frame.midY - height / 2,
width: width,
height: height)
}
}
class ViewController: UIViewController {
let button = UIButton(type: .system)
override func viewDidLoad() {
super.viewDidroad()
view.backgroundColor = .green
view.addSubview(button)
button.setTitle("๋ฒํผ", for: .normal)
//๋ฒํผ์ ์ก์
๋ฃ์ด์ฃผ๊ธฐ
button.addTarget(self, action: #selector(didTapButton(_:)), for: .touchUpInside) //#selector๋ฅผ ์ ์ด์ผ ํ๋ ์ด์ ๋ ๋ฒํผ์ ์ก์
์ ์ ๋ฌํ ๋ objectc๋ก ์ ๋ฌํด์ผ ํ๊ธฐ๋๋ฌธ.
button.frame.size = CGSize(width: 100, height: 100) // ๋ฒํผ ์ฌ์ด์ฆ ์ก์์ฃผ๊ธฐ
let width: CGFloat = 200
let height: CGFloat = 100
button.frame = CGRect (x: view.frame.midX - width / 2,
y: view.frame.midY - height / 2,
width: width,
height: height)
}
@objc //selector ์์๋ @objc๊ฐ ๋ค์ด๊ฐ ํจ์๋ฅผ ๋ง๋ค์ด์ค์ผํจ
func didTapButton(_ sender: UIButton){ // _ sender ์๋ต๊ฐ๋ฅ. ์์์ sender์ ์ฌ์ฉํ์ฌ ๊ตฌ๋ถ์ด ๊ฐ๋ฅ(๋ฒํผ์ด ์ฌ๋ฌ๊ฐ์ธ๊ฒฝ์ฐ)
print("Button Tapped")
}
}