ios - Can't add constraints between UICollectionView cell and the cell subview -


well, after run app, crashes , reason is: "unable install constraint on view. constraint reference outside subtree of view? that's illegal." image subview of cell, doing wrong?

            let image = uiimageview(frame: cgrect(x: 0, y: 0, width: 300, height: 50))             image.image = uiimage.init(named: "bitmap")              cell.contentview.addsubview(image)              let bottomconstr = nslayoutconstraint(item: image, attribute: .bottom, relatedby: .equal, toitem: cell.contentview, attribute: .bottom, multiplier: 1, constant: 0)             //let leftconstr = nslayoutconstraint(item: image, attribute: .leading, relatedby: .equal, toitem: cell.contentview, attribute: .leading, multiplier: 1, constant: 0)             //let rightconstr = nslayoutconstraint(item: image, attribute: .trailing, relatedby: .equal, toitem: cell.contentview, attribute: .trailing, multiplier: 1, constant: 0)             let heightconstr = nslayoutconstraint(item: image, attribute: .height, relatedby: .equal, toitem: nil , attribute: .notanattribute, multiplier: 1, constant: 10)              image.addconstraint(bottomconstr)             //image.addconstraint(leftconstr)             //image.addconstraint(rightconstr)             image.addconstraint(heightconstr) 

you need add constraint on superview. so, add on cell contentview.

  cell.contentview.addconstraint(bottomconstr)   cell.contentview.addconstraint(heightconstr) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -