I have this UICollectionViewController
class code :
class ViewController1: UICollectionViewController , UICollectionViewDelegateFlowLayout{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.collectionView?.backgroundColor = UIColor(white: 0.95, alpha: 1)
self.collectionView?.alwaysBounceVertical = true
collectionView?.registerClass(Cell.self, forCellWithReuseIdentifier: "cellid")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCellWithReuseIdentifier("cellid", forIndexPath: indexPath)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 100)
}
}
class Cell :UICollectionViewCell {
//var i : Int = 0
override init(frame: CGRect) {
super.init(frame: frame)
self.setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var namelabel : UILabel = {
let label = UILabel()
label.text = "test"
//label.font = UIFont.boldSystemFontOfSize(14)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var distanzalabel : UILabel = {
let label = UILabel()
label.text = "200KM"
//label.font = UIFont.boldSystemFontOfSize(14)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var imageV : UIImageView = {
let imageView = UIImageView()
//imageView.frame = CGRectMake(0, 0, 450 , 150);
imageView.image = UIImage(named: "2.jpg")
imageView.contentMode = .ScaleAspectFit
//imageView.clipsToBounds = true
imageView.backgroundColor = UIColor.greenColor()
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
var imageV1 : UIImageView = {
let imageView = UIImageView()
imageView.frame = CGRectMake(0, 0, 20 , 20);
imageView.image = UIImage(named: "User Male Filled.png")
imageView.contentMode = .ScaleAspectFit
//imageView.clipsToBounds = true
imageView.backgroundColor = UIColor.blackColor()
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
func setupViews(){
backgroundColor = UIColor.whiteColor()
self.addSubview(namelabel)
self.addSubview(distanzalabel)
self.addSubview(imageV)
self.addSubview(imageV1)
let lunghezza = self.frame.width
let result = lunghezza - 100
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[v0(\(lunghezza))]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-\(result)-[v0(30)]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV1]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-5-[v0(33)]-4-[v1]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV , "v1" : namelabel]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-5-[v0(33)]-4-[v1]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV , "v1" : imageV1]))
}}
My problem is that when I execute this code I get this :
http://postimg.org/image/jqwjt0o2f/
as you can see by the image , the two images are too small respect the UIImageview 's size , and I want that for example if I have the UIImageView
' size is 30x30 the image fills all imageView.
I select color for two ImageView for show you the real size of this UIImageView
How do I solve this problem?