The problem that I have is that somehow the UIView gets an undesirable padding. It seems that the UIView frame resizes itself based on the UIImage height.
These are my constraints on the UIView
Cell Configuration:
// Configure the cell...
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: cell.testView.frame.width, height: cell.testView.frame.height))
imageView.image = UIImage(named: "eiffel.JPG")
imageView.autoresizingMask = .FlexibleWidth
imageView.contentMode = .ScaleAspectFit
imageView.center = cell.testView.center
imageView.clipsToBounds = true
imageView.translatesAutoresizingMaskIntoConstraints = false
cell.testView.addSubview(imageView)
let bottomMarginConstraint = NSLayoutConstraint(item: imageView, attribute: .Bottom, relatedBy: .Equal, toItem: cell.testView, attribute: .Bottom, multiplier: 1, constant: 0)
let topMarginConstraint = NSLayoutConstraint(item: imageView, attribute: .Top, relatedBy: .Equal, toItem: cell.testView, attribute: .Top, multiplier: 1, constant: 0)
let trailingMarginConstraint = NSLayoutConstraint(item: imageView, attribute: .Left, relatedBy: .Equal, toItem: cell.testView, attribute: .Left, multiplier: 1, constant: 0)
let leadingMarginConstraint = NSLayoutConstraint(item: imageView, attribute: .Right, relatedBy: .Equal, toItem: cell.testView, attribute: .Right, multiplier: 1, constant: 0)
//let widthConstraint = NSLayoutConstraint(item: imageView, attribute: .Width, relatedBy: .Equal, toItem: .None, attribute: .NotAnAttribute, multiplier: 1, constant: imageView.superview!.frame.width)
let constraints = [bottomMarginConstraint, topMarginConstraint, leadingMarginConstraint, trailingMarginConstraint]
cell.testView.addConstraints(constraints)
The UIView is the one with the light green background and the Cell the one with the pink background.