Я пытаюсь создать ячейку программно, не используя рассказ, но я натыкаюсь на некоторые проблемы. Код ячейки следующий.Программа UICollectionViewCell Programmatically
import UIKit
class ProductCategoryCollectionViewCell: UICollectionViewCell {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupCell()
}
var productCategoryImageView :UIImageView!
func setupCell(){
//seting up the imageView as subView
productCategoryImageView = UIImageView()
productCategoryImageView.translatesAutoresizingMaskIntoConstraints = false
let subViewDictionary = ["productCategoryImageViewKey" : productCategoryImageView]
let productCategoryImageViewWidth = contentView.bounds.size.width
let productCategoryImageViewHeight = contentView.bounds.size.height
let productCategoryImageViewHorizontalConstrain = NSLayoutConstraint.constraintsWithVisualFormat("H:[productCategoryImageViewKey(\(productCategoryImageViewWidth))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: subViewDictionary)
let productCategoryImageViewVerticalConstrain = NSLayoutConstraint.constraintsWithVisualFormat("V:[productCategoryImageViewKey(\(productCategoryImageViewHeight))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: subViewDictionary)
productCategoryImageView.addConstraints(productCategoryImageViewHorizontalConstrain)
productCategoryImageView.addConstraints(productCategoryImageViewVerticalConstrain)
contentView.addSubview(productCategoryImageView)
contentView.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.4)
}
}
Я пытаюсь создать subImageView, который будет размер ячейки, однако, не масштабироваться до до размера ячейки.
Спасибо ... Почему я не подумал об этом. спасибо – progammingBeignner