iOS
[iOS] - UILabel
No.401
2020. 8. 2. 10:00
- UILabel 내용 정리
- Snapkit으로 ui-component들을 배치합니다.
- SnapKit의 기본 지식은 2020/08/01 - [iOS] - iOS - SnapKit : Layout 정리를 참고.
import Foundation
import SnapKit
class TestUILabelVC: UIViewController {
lazy var noB_Label : UILabel = {
// Label 생성 => 가로 300 , 세로 300
let lbl : UILabel = UILabel (frame : CGRect (x: 0 , y: 0 , width: 300 , height: 300 ))
lbl.backgroundColor = UIColor.black
lbl.text = "No.B.Rain 노비의 문서"
lbl.textColor = UIColor.yellow
// Text 정렬 (중앙)
lbl.textAlignment = NSTextAlignment.center
// 둥근 모서리 => 둥근 모서리는 컨탠츠 높이의 5%가 가장 적당하고 이쁨(개인적으로..)
lbl.layer.masksToBounds = true
lbl.layer.cornerRadius = 150 * 0.05
// 그림자
lbl.shadowColor = UIColor.black
return lbl
}()
override func viewDidLoad() {
super.viewDidLoad()
//UILabel 화면에 추가
self.view.addSubview(noB_Label)
//화면 중앙 배치
noB_Label.snp.makeConstraints { (constraint) in
constraint.center.equalTo(self.view)
}
}
}