-
Notifications
You must be signed in to change notification settings - Fork 3
EmptyView
Hiju edited this page Dec 1, 2021
·
1 revision
import UIKit
final class EmptyView: UIView {
// MARK: - Properties
private let imageView = UIImageView()
private let titlelabel = UILabel()
// MARK: - Init
override init(frame: CGRect) {
super.init(frame: frame)
configureLayout()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
configureLayout()
}
// MARK: - Functions
private func configureLayout() {
addSubview(imageView)
addSubview(titlelabel)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
imageView.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: -50).isActive = true
imageView.widthAnchor.constraint(equalToConstant: self.frame.width / 5).isActive = true
imageView.heightAnchor.constraint(equalToConstant: self.frame.width / 5).isActive = true
titlelabel.translatesAutoresizingMaskIntoConstraints = false
titlelabel.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
titlelabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 40).isActive = true
}
func apply(title: String, image: UIImage) {
imageView.image = image
imageView.contentMode = .scaleAspectFit
imageView.tintColor = .boosterGray
titlelabel.text = title
titlelabel.textColor = .boosterGray
titlelabel.numberOfLines = 3
titlelabel.textAlignment = .center
titlelabel.font = .notoSansKR(.regular, 17)
}
}
- 뷰의 center에 사진과 아래 레이블로 아무것도 없을 때 명시를 해줄 수 있습니다.
- apply 메소드를 이용하여 사진과 레이블을 넣을 수 있습니다.