0
我有一個UICollectionView,它呈現瀑布式佈局中的圖像,這非常完美。我現在試圖在每張圖片上添加說明。面臨的挑戰是我試圖以編程方式添加UILabel,但它沒有出現。我確定label.text包含文本。以編程方式將UILabel添加到UICollectionViewCell
class NTWaterfallViewCell :UICollectionViewCell, NTTansitionWaterfallGridViewProtocol{
var photoName = ""
var imageName : String?
var imageViewContent : UIImageView = UIImageView()
var label:UILabel = UILabel()
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.lightGray
contentView.addSubview(imageViewContent)
contentView.addSubview(label)
}
override func layoutSubviews() {
super.layoutSubviews()
imageViewContent.frame = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)
imageViewContent.loadImageWithURL(imageName!)
label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.text = photoName
}