[UIKit] hierarchy, 계층구조
UIKit은 'User Interface Kit'으로 사용자 인터페이스를 구성하는데 사용하는 인터페이스이다.NSObject는 대부분의 Objective-C 클래스의 루트클래스이자, Swift에서도 기반 클래스가 되며, 기본적인 객체의
usiacode.tistory.com
[NSObject - UIResponder - UIView - UILabel]
UILabel은 텍스트를 표시하는 기본적인 객체로 간단한 텍스트 표시부터 스타일링까지 다양한 기능을 제공한다.
Property, Method
/* Property */
label.text = "텍스트 입력" // 텍스트를 입력
label.textColor = .red // 텍스트의 색깔 변경 (UIColor)
label.font = UIFont.systemFont(ofSize: 24) // 폰트 설정 (텍스트 크기, 굵기 등)
label.textAlignment = .center // 정렬 설정
label.numberOfLines = 0 // 텍스트의 최대 줄 수 (0으로 하면 무한)
label.backgroundColor = .white // 배경색
label.inEnabled = true // 활성화 또는 비활성화
/* Method */
label.sizeToFit() // label 의 크기를 텍스트에 맞게 조정
스토리보드에서 추가


코드로 추가
private lazy var myLabel: UILabel = {
let label = UILabel()
label.text = "텍스트 입력"
label.font = UIFont.systemFont(ofSize: 18)
label.textAlignment = .center
// label.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
// label.sizeToFit()
view.addSubview(label) // 추가
return label
}()
[오토레이아웃]
//func myLabelSetup() {
// myLabel.translatesAutoresizingMaskIntoConstraints = false
//
// NSLayoutConstraint.activate([
// myLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30),
// myLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30),
// myLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 30),
// myLabel.heightAnchor.constraint(equalToConstant: 40)
// ])
//}
'UIKit' 카테고리의 다른 글
| [UIKit] UISlider (0) | 2024.07.29 |
|---|---|
| [UIKit] UIButton (0) | 2024.07.29 |
| [UIKit] hierarchy, 계층구조 (0) | 2024.07.29 |
| [UIKit CodeSnippets] UITextField Snippet (Only-code) (2) | 2024.07.24 |
| [UIKit CodeSnippets] UISlide Snippet (Only-code) (0) | 2024.07.24 |