Created
November 21, 2019 20:04
-
-
Save anupamchugh/1564acd2d5ddd8c7fd226e1f98aabc2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class CustomCell: UICollectionViewCell { | |
var data: CustomData? { | |
didSet { | |
guard let data = data else { return } | |
imageView.image = data.frameImage | |
label.text = data.faceQualityValue | |
} | |
} | |
fileprivate let imageView: UIImageView = { | |
let iv = UIImageView() | |
iv.translatesAutoresizingMaskIntoConstraints = false | |
iv.contentMode = .scaleAspectFill | |
iv.clipsToBounds = true | |
iv.layer.cornerRadius = 8 | |
return iv | |
}() | |
fileprivate let label: UILabel = { | |
let label = UILabel() | |
label.translatesAutoresizingMaskIntoConstraints = false | |
label.textAlignment = .center | |
label.font = .systemFont(ofSize: 12) | |
return label | |
}() | |
override init(frame: CGRect) { | |
super.init(frame: .zero) | |
contentView.addSubview(imageView) | |
imageView.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true | |
imageView.heightAnchor.constraint(equalToConstant: 60).isActive = true | |
imageView.widthAnchor.constraint(equalToConstant: 60).isActive = true | |
imageView.centerXAnchor.constraint(equalTo: contentView.centerXAnchor).isActive = true | |
contentView.addSubview(label) | |
label.topAnchor.constraint(equalTo: imageView.bottomAnchor).isActive = true | |
label.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true | |
label.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true | |
label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment