iOS 앱 프로그래밍

[iOS Dev] Hello World! (Storyboard, programmatically)

후추멍멍이 2021. 11. 16. 18:39
iOS App Development Study - How to print "Hello World!" in Storyboard and in Code
iOS 어플 개발 공부 - 두 가지 방법으로 "Hello World!" 출력하기(스토리보드, 코드) 
  • 개발 환경 : MacBook Pro (13-inch, M1, 2020), Monterey
  • XCode : Version 13.1 (13A1030d)
  • 시뮬레이터 : iPhone 11

 

 

 

 

import UIKit

class ViewController: UIViewController {
	let textLabel = UILabel()
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
		self.view.addSubview(textLabel)
		
		// UILabel에 들어갈 String
		textLabel.text = "Hello World!"
		
		// UILabel 배경 색
		textLabel.backgroundColor = .red
	
		// UILabel 텍스트 색
		textLabel.textColor = .white
		
		// UILabel 프레임 값 설정
		textLabel.frame = CGRect(x: 100, y: 200, width: 150, height: 30)
		// (100, 200)인 (x, y) 좌표에서 가로 150 높이 30인 프레임 셋팅
		
	}


}