4

In code I added 4 constraints. But when I run the app, in UI debugger, it shows additional 6 constraints? It should be all clear with these 4 I added. I don't know what I'm doing wrong?

let leftConstr   = NSLayoutConstraint(item: image, attribute: .leading, relatedBy: .equal, toItem: cell.contentView, attribute: .leading, multiplier: 1.0, constant: 0.0)
let bottomConstr = NSLayoutConstraint(item: image, attribute: .bottom, relatedBy: .equal, toItem: cell.contentView , attribute: .bottom, multiplier: 1.0, constant: 0.0)
let highthConstr = NSLayoutConstraint(item: image, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 15)
let widthConstr  = NSLayoutConstraint(item: image, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 50)
cell.contentView.addConstraints([highthConstr, widthConstr, bottomConstr, leftConstr])

Here is the screenshot of my UI debugger

screenshot.

pkamb
  • 33,281
  • 23
  • 160
  • 191
  • 1
    I have seen this happen as well. If I try to make my constraints programmatically, it seems like it autogenerates the ones I don't create to make the scenario work. Perhaps 'translatesAutoresizingMaskIntoConstraints' is what did that. – Sethmr Nov 17 '16 at 17:15

1 Answers1

4

Maybe you can try to add this line of code before :

image.translatesAutoresizingMaskIntoConstraints = false
Matthias
  • 999
  • 11
  • 25